1
我有他的模型:使用mongoose更新mongo中的二級數組返回意外標記「。」
var field = {
questionSets: [
{
name : "",
questions: [
{
question: {type: String, required: true},
answer: {type: String},
}
]
}
]
}
而這個查詢:
SubjectiveForm.update(
{_id:doc._id, questionSets.$._id:req.params.set_id},
{$pushAll: {questions:req.body}},
{upsert:true},
function(err, questions){
console.log("err", err);
console.log("err", questions);
}
)
,但此行{_id:doc._id, questionSets.$._id:req.params.set_id},
上questionSets.$
返回Unexpected token .
。
BTW的req.body
看起來是這樣的(一個JSON):
[
{
"question" : "Added 1?"
},
{
"question" : "Added 2?"
}
]
WTF?我很盲目。 >。<感謝此。無論如何,上面的查詢在執行時返回'{ok:0,n:0,nModified:0}'它仍然不會更新文檔。 – CENT1PEDE
是的,所以你的查詢現在不匹配任何文件 –
但是數據存在:/ – CENT1PEDE