Reputation: 47
{
"_id" : ObjectId("54fd4ddaa037ba481d794f5e"),
"question" : "let me go?",
"choices" : [
{
"text" : "yes",
"_id" : ObjectId("54fd4ddaa037ba481d794f60"),
"votes" : [ ]
}, {
"text" : "y",
"_id" : ObjectId("54fd4ddaa037ba481d794f5f"),
"votes" : [ ]
}
],
"__v" : 0
}
I want to change the value "y" to "no", How? wish your answer thanks
Upvotes: 2
Views: 32
Reputation: 103305
Use the $set
operator together with the $ positional
operator in your update to set elements in array without explicitly specifying the position of the element in the array i.e.
db.collection.update(
{ "question": "let me go?", "choices.text": "y" },
{ $set: { "choices.$.text": "no" } }
);
Upvotes: 1