MongoDB の $set & $-operators に問題があります。既存の配列を変更しようとしています
私の更新方法は次のようになります (Clojure/Monger で記述されているため、正確なコピーを取得できません)。
bulk.find({
_id: 2,
channelStatuses.channel: {$eq: "BAR"}
}).update({
$set: {"channelStatuses.$.status": "error" }
});
私のデータは次のようになります。
{
"_id" : "1",
"channelStatuses" : [
{
"channel" : "FOO",
"status" : "done"
}
]
},
{
"_id" : "2",
"channelStatuses" : [
{
"channel" : "BAR",
"status" : "done"
}
]
},
{
"_id" : "3",
"channelStatuses" : [
{
"channel" : "BAZ",
"status" : "error"
}
]
},
{
"_id" : "3",
"channelStatuses" : []
}
したがって、ドキュメントの channelStatuses オブジェクトのステータスを _id = 2 に変更する必要があります。
代わりに、channelStatuses 配列内に新しいオブジェクトを作成し、ドキュメントは次のようになります。
{
"_id" : "2",
"channelStatuses" : [
{
"channel" : "BAR",
"status" : "done"
},
{
"channel" : "BAR",
"status" : ""
}
]
},