私はこのクエリを使用しています:
Model.update(
{_id: req.params.questions_id, "doc.questionSets.$._id": req.params.set_id},
{$pushAll: {"questions": req.body}},
{upsert:true},
function(err, questions){
console.log("err", err);
console.log("err", questions);
}
)
ルート呼び出し:
localhost:3131/api/v0.1/charting/questions/56cff03e9ff240192da2fa34/set/56cff04e9ff240192da2fa3a/add-new-question
どこ :charting/questions/:questions_id/set/:set_id/add-new-question
文書データ:
/* 1 */
{
"_id" : ObjectId("56cff03e9ff240192da2fa34"),
"questionSets" : [
{
"name" : "Physical exam questions",
"_id" : ObjectId("56cff03e9ff240192da2fa35"),
"questions" : [
{
"question" : "What is love?",
"answer" : "",
"_id" : ObjectId("56cff03e9ff240192da2fa39")
}
]
},
{
"name" : "Brain questions",
"_id" : ObjectId("56cff04e9ff240192da2fa3a"),
"questions" : [
{
"question" : "What is love?",
"answer" : "",
"_id" : ObjectId("56cff04e9ff240192da2fa3e")
}
]
}
],
"updatedAt" : ISODate("2016-02-26T06:26:39.330Z")
}
questionSets[0].questions
そして、この JSON オブジェクトを次の場所にプッシュします。
[
{
"question" : "Added 1?"
}
]
しかし、クエリは{ ok: 0, n: 0, nModified: 0 }を返し、ドキュメントは更新されていません。ここで何が間違っていますか?ありがとう。