I have a built-in document in mongodb, how can I delete only one address where pincode: 140901 and update where pincode: 152364
db.add_fun.insert({ "_id" : ObjectId("5a82e6dc1139b572569fa785"), "name" : "Vikas", "salary" : 72.0, "address" : [ { "address_id" : ObjectId("5a82f0e51139b572569fa78c"), "address" : "Mullanpur ", "pincode" : "140901", "country" : "India" }, { "address_id" : ObjectId("5a82f0e51139b572569fa78d"), "address" : "mohali ", "pincode" : "152364", "country" : "India" } ] })
I try this but not work
db.add_fun.update({}, { $pull: { address: { $elemMatch: { pincode: "140901" } } } }, { multi:true } )
want to delete this
{ "address_id" : ObjectId("5a82f0e51139b572569fa78c"), "address" : "Mullanpur ", "pincode" : "140901", "country" : "India" },
and want to get this result
{ "_id" : ObjectId("5a82e6dc1139b572569fa785"), "name" : "Vikas", "salary" : 72.0, "address" : [ { "address_id" : ObjectId("5a82f0e51139b572569fa78d"), "address" : "mohali ", "pincode" : "152364", "country" : "India" } ] }
source share