我想增加資料庫中的當前數字。
示例:如果資料庫中的數字為 0,我希望它在每次使用 PostImage 命令時增加 1。
錯誤:當我 console.log(debug) 它給出 undefined
const attachment = await interaction.options.getAttachment("input");
const caption = await interaction.options.getString("caption");
const channel = client.channels.cache.get("988214204660064286");
const embed = new MessageEmbed()
.setAuthor({ name: `${username} Posted`, iconURL: `${profilePicData}` })
.setColor("#303236")
.setDescription(`${caption}`)
.setImage(`${attachment.url}`)
.setFooter({ text: `user ID: ${userId}`, iconURL: `${profilePicData}` })
channel.send({ embeds: [embed] }).then(async (msg) => {
await msg.react("??");
await msg.react("??");
});
db.findOneAndUpdate({
UserId: userId,
PostAmount: 1
})
const dubug = data.map((x) => `${x.PostAmount}`).join('\n');
console.log(dubug)
uj5u.com熱心網友回復:
增加使用mongoose資料{$inc: {your_data}}
db.findOneAndUpdate({
UserId: userId,
PostAmount: 1 //You can now remove these one.
}, {$inc: {PostAmount: 1}}, async(err, data) => {
if(data) {
data.PostAmount = 1;
await data.save();
}
})
您應該洗掉這些代碼行PostAmount: 1因為
UserId會在資料庫中找到它自己的資料。
uj5u.com熱心網友回復:
要將 的值增加PostAmount1,您可以簡單地獲取檔案,將 的值更改PostAmount為PostAmount 1并保存檔案
let doc = await db.findOne({ UserId: userId });
doc.PostAmount = doc.PostAmount 1;
await doc.save();
除此之外,debug回傳 undefined 因為它沒有定義。這可能是因為在除錯定義中它嘗試映射data我也沒有看到定義的映射。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/494469.html
