我正在制作一个不协调的bot进行审核,我需要将惩罚数量存储在数据库中,其工作方式如下:每次警告某人时,totalPunishments计数器应增加一个,警告计数器也应增加一个。通过一些谷歌搜索,我发现了大约$ inc语句。我尝试使用它,并且警告计数器逐渐变好。但是总计数器完全不变。
这是我的代码:
await mongo().then(async mongoose => {
try {
const userInfo = await punishmentSchema.findOne({_id: guild.id, userId: member.id});
if(userInfo) {
await punishmentSchema.findOneAndUpdate({
_id: guild.id,
userId: member.id
}, {
$inc: {'totalPunishments': 1},
$inc: {'warnings': 1},
lastPunishment: timestamp('YYYYMMDDHHMM')
})
} else {
await punishmentSchema.create({
_id: guild.id,
userId: member.id,
totalPunishments: 1,
warnings: 1,
mutes: 0,
kicks: 0,
lastPunishment: timestamp('YYYYMMDDHHMM')
})
}
} catch(e) {
console.log(e);
} finally {
mongoose.connection.close();
}
这是我的架构:
const mongoose = require('mongoose');
const reqString = {
type: String,
required: true
}
const punishmentSchema = mongoose.Schema({
_id: reqString,
userId: reqString,
totalPunishments: Number,
warnings: Number,
mutes: Number,
kicks: Number,
lastPunishment: reqString
})
module.exports = mongoose.model('user', punishmentSchema);
谁能帮我?
您可能需要将2个$ inc道具合并为一个
$inc: {'totalPunishments': 1, 'warnings': 1},
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句