Reputation: 352
{
"_id" : ObjectId("604f3a4d5ad6670507b7ead4"),
"socialStats" : [
{
"$ref" : "socialStats",
"$id" : ObjectId("604f4f883b18ab7883ce3aba")
},
{
"$ref" : "socialStats",
"$id" : ObjectId("604f5000da171840ec32bd3d")
}
],
},
{
"_id" : ObjectId("604f3a4d5ad6670507b7ead4"),
"socialStats" : [
{
"$ref" : "socialStats",
"$id" : ObjectId("604f4f883b18ab7883ce3aba")
},
{
"$ref" : "socialStats",
"$id" : ObjectId("604f5000da171840ec32bd3d")
}
],
}
i have a mongo collection "asset" i want to update "socialStats":[] in all the records of collection What will be the query?
Upvotes: 1
Views: 537
Reputation: 2392
You can use update Method with blank search Object and with {multi : true }
option.
Here, I use $set operator
db.collection.update({},
{
"$set": {
"socialStats": []
}
},
{
"multi": true
})
If you not use {multi: true}
only one document is going to be updated.
OR
You can also do this by using db.collection.updateMany() method.
db.collection.updateMany({},
{
"$set": {
"socialStats": []
}
})
Upvotes: 2