Home:ALL Converter>MongoDB update where multiple conditions

MongoDB update where multiple conditions

Ask Time:2019-10-19T15:22:21         Author:pekingduct

Json Formatter

I am attempting to update information on one of my fields where two different conditions are met. I don't know if this is the right idea on how to do it, but guidance would be appreciated. I am met with the error of: "unknown top level operator: $eq"

db.shop.update({"$and":[{"item.name":"Milk"}, {"$eq":{"item.price":2.80}}]}, {"$set": {"item.expiry":"21/10/19"}});

Author:pekingduct,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58461447/mongodb-update-where-multiple-conditions
sushant mehta :

You can use $and as\n\ndb.shop.update(\n {\"$and\":[{\"$eq\":[\"item.name\",\"Milk\"]}, {\"$eq\":[\"item.price\",2.80]}]}, \n {\"$set\": {\"item.expiry\":\"21/10/19\"}}\n)\n\nbut it is equivalent to below and will be faster as expression takes time to compute\n\ndb.shop.update(\n {\"item.name\":\"Milk\",\"item.price\":2.80}, \n {\"$set\": {\"item.expiry\":\"21/10/19\"}}\n)\n",
2019-10-19T07:29:40
yy