【发布时间】:2023-04-07 17:49:02
【问题描述】:
我怎样才能使update 工作?
当前错误:
MongoError: cannot use the part (cartheft of crimes.0.cartheft.chance) to traverse the element
我也尝试输入 $,但后来我得到:
(node:10360) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): MongoError: Too many positional (i.e. '$') elements found in path 'crimes.$.cartheft.$.chance'
代码:
cartheft_crime.update({
userid: req.user._id,
"crimes.location": 1,
"crimes.cartheft.theftid" : 1,
}, {$inc: {"crimes.$.cartheft.chance": 1000}}).then(function (response) {
res.json(response);
});
型号:
userid : String,
crimes: [{
location: {type: Number, default: 1},
lastcartheft: {
time: {type: Number, default: 1},
type: {type: Number, default: 1},
},
cartheft: [
{
id: {type: Number, default: 1},
theftid: {type: Number, default: 1},
chance: {type: Number, default: 200},
success: {type: Number, default: 0},
failure: {type: Number, default: 0},
},
],
}],
ip: String
【问题讨论】:
标签: javascript database mongodb mongoose