所以我遇到数据库无法正确更新的问题:
User.updateOne({_id: id}, {
$inc: {thonk: 1}
}, (err, res) => {
if (err) throw err;
console.log(res);
session.userdata.thonk++;
data = session.userdata.username + ' You auto thonked a total of ' + session.userdata.thonk;
session.userdata.autos--;
session.save();
battle(io, socket);
io.sockets.connected[socket.id].emit('auto-result', data);
});
如果我管理结果:{ n: 0, nModified: 0, ok: 1 }
这是User模型的架构。奇怪的是我之前已经对此进行了测试,并且可以正常工作。现在,它只是不想。
const UserSchema = mongoose.Schema({
email:{
type: String,
required: true
},
username:{
type: String,
required: true
},
password:{
type: String,
required: true
},
registered: {
type: String,
default: today
},
rank: {
type: Number,
default: 1
},
currency: {
type: Object,
default: {
cs: 100,
os: 100
},
},
thonk: {
type: Number,
default: 0
}
});