【发布时间】:2014-06-28 05:28:06
【问题描述】:
我正在尝试使用 Mongoose 制作动态条件,但它并没有像我想象的那样工作。
代码是这样的
id = req.params.questionId;
index = req.params.index;
callback = function(err,value){
if(err){
res.send(err)
}else{
res.send(value)
}
};
conditions = {
"_id": id,
"array._id": filterId
};
updates = {
$push: {
"array.$.array2."+index+".answeredBy": userId
}
};
options = {
upsert: true
};
Model.update(conditions, updates, options, callback);
如您所见,我正在尝试使用“索引”变量创建动态条件。这样可以吗?
提前谢谢你!
【问题讨论】:
标签: javascript node.js mongodb mongoose database