我试图使用猫鼬$ inc运算符将数组中的数字更新为1 如果我想专门更新“人”,这将非常有效
let picked= "name user picked";
Event.updateOne({_id: 2, "contestants.usersid" : 2019 } ,
{$inc : { "contestants.$.person" : 1} },
function(err) {
if(err){
console.log(err);
}else {
let name = "You voted for " + picked;
console.log("increased vote by 1");
res.render("results", {
voteNUM: name
});
}
}
);
我如何用选取的(变量)替换“人”。我试过了,但是没用
Event.updateOne({_id: 2, "contestants.usersid" : 2019 } ,
{$inc : { contestants.$.picked : 1} },
function(err) {
if(err){
console.log(err);
}else {
let name = "You voted for " + picked;
console.log("increased vote by 1");
res.render("results", {
voteNUM: name
});
}
}
);
任何帮助将不胜感激