Reputation: 13
I have an existing mongo collection. Each document inside looks similar to this:
document1:
{
"_id": ObjectId("..."),
"subId": 11,
...
}
document2:
{
"_id": ObjectId("..."),
"subId": 11,
...
}
...
documenntN:
{
"_id": ObjectId("..."),
"subId": 11,
...
}
Is it possible to run a db.collection.update query in such a way as I can replace the "subId": 11 to "subId": 22?
output:
document1:
{
"_id": ObjectId("..."),
"subId": 22,
...
}
document2:
{
"_id": ObjectId("..."),
"subId": 22,
...
}
...
documenntN:
{
"_id": ObjectId("..."),
"subId": 22,
...
}
Upvotes: 0
Views: 759
Reputation: 1404
db.collection.updateMany({ subId: 11 }, { $set: { subId: 22 } })
Upvotes: 1