I'm making a discord bot in discord.js and I want to make a database that keeps track of user messages, I've got the tracking part and the database structure down, which goes as follows:
_id: guildId,
metrics: {
[userId]:
{
messageCount: 1
}
}
I'm using a mongoose schema, so how would I use schema.findoneandupdate to incrementally increase the messageCount value?
You can use $inc
operator:
More detail: https://docs.mongodb.com/manual/reference/operator/update/inc/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.