Comment puis-je faire ce update
de travail?mise à jour retour correspondant
erreur actuelle:
MongoError: cannot use the part (cartheft of crimes.0.cartheft.chance) to traverse the element
J'ai aussi essayé de mettre $, mais je reçois:
(node:10360) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): MongoError: Too many positional (i.e. '$') elements found in path 'crimes.$.cartheft.$.chance'
Code
:
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);
});
modèle
:
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
Comment alors la bonne façon d'accomplir ce soit? – maria