I need to update multiple nested sub document field which eid:63b3f577763b3f5777
in the document status to true or false,
I try updateMany query but its not working...
I know my schema is more nested but i don't have any other option
this is my document model
{
"_id":"63b3b63b3f57774024"
"name":"dev"
"email":"[email protected]"
"image":"https://sgp1.digitaloceanspaces.com"
"tickets":[
{
"sid":"63b363b3f5777f5768"
"eid":"63b3f577763b3f5777"
"name":"john"
"status":false
_id:{
"$oid":"63b463b3f5777178c4"
}
},
{
"sid":"63b363b3f5777f5769"
"eid":"63b3f577763b3f5777"
"name":"viswam"
"status":false
"_id":{
"$oid":"63b463b3f5777178c5"
}
{
"sid":"63b63b3f57773f5770"
"eid":"63b3f577763b3f5777"
"name":"dev"
"status":false
"_id":{
"$oid":"63b63b3f57774178c6"
}
{
"sid":"63b63b3f57773f5771"
"eid":"63b3f577763b3f5777"
"name":"kumar"
"status":false
"_id":{
"$oid":"63b463b3f5777178c7"
}
""__v":0
}]
I need to update tickests.status to true or false.How to check this field?
Can anyone suggest me the exact query to find this?
Specification
node: v14.17.3,
mongoose: "^6.6.5",
mongodb:Atlas
CodePudding user response:
Try this code:
db.collections.updateMany(
{ "tickets": { "$elemMatch": { "eid": "63b3f577763b3f5777" } } }
{ "$set": { "tickets.$.status": false } }
)
If you have any query. Please let me know
CodePudding user response:
db.collections.updateMany
({"tickets.eid":"63b3f577763b3f5777"},
{"$set":{"tickets.$[elem].status":"false"}},
{"arrayFilters": [{"elem.eid":"63b3f577763b3f5777"}]
})