I have a beautiful little MongoDB collection with the following object:
{
"_id" : ObjectId("5919df60adb8170833fb4fa9"),
"a" : [
{
"_id" : ObjectId("5919df60adb8170833fb4faa"),
"b" : {
"c" : true,
"d" : [
{
"e" : "cats",
},
{
"f" : "dogs",
}
]
}
}
]
}
One can set this up by running mongo then running the following commands:
use cats
db.wonk.insertOne({"_id":ObjectId("5919df60adb8170833fb4fa9"),"a":[{"_id":ObjectId("5919df60adb8170833fb4faa"),"b":{"c":true,"d":[{"e":"cats",},{"f":"dogs",}]}}]})
I want to set the value of ‘e’ to ‘meow’, but can’t figure out how to query up that object. I thought the following would find e but no dice:
db.wonk.find({a: { $elemMatch: { 'b': { 'd': { $elemMatch: { 'e': 'cats' } } } } }})
My question is: how can I set the value of e to meow? Any help others can offer on this question would be hugely appreciated!