I want to increase the current number in the database.
Example: If the number in the database is 0 I want it to increase by 1 every time I use the PostImage command.
The Error: When I console.log(debug) It gives 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: }).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)
2
Answers
To increase the value of
PostAmount
by 1, you can simply get the document, change the value ofPostAmount
toPostAmount + 1
and save the documentBesides that,
debug
returns undefined because it is not defined. It is probably because in the debug definition it tries to mapdata
which I don’t see defined either.Increasing a data on
mongoose
uses{$inc: {your_data}}