I want to update an inner element state field in a mongodb collection, I have given below the collection and my mongodb update statement.
{
"_id" : ObjectId("561b4c83e3603fcd1badaeb3"),
"continent" : "Asia",
"countries" : [
{
"country" : "India",
"_id" : ObjectId("561b83c3626fca4a23c0131f"),
"states" : [
{
"state" : "Kerala"
}
........ many other states
]
}
],
"__v" : 0
}
I used this mongodb query.
db.places.update({ "_id" : ObjectId("561b4c83e3603fcd1badaeb3"), "countries.states.state": "Kerala" },{ $set: { "country.$.states.$.state": "Tamilnad" } } );
Expected result
{
"_id" : ObjectId("561b4c83e3603fcd1badaeb3"),
"continent" : "Asia",
"countries" : [
{
"country" : "India",
"_id" : ObjectId("561b83c3626fca4a23c0131f"),
"states" : [
{
"state" : "Goa"
}
........ many other states
]
}
],
"__v" : 0
}
Please help me.