Reputation: 107
Let say I have a collection. I want to change the field name and value in the whole collection like this
Current:
language:"en",
documentId:"123"
Desired:
languages:["en"],
documentIds:["123"]
db.foo.... Thank you in advance
Upvotes: 0
Views: 49
Reputation: 8705
Query
{}
and updateMany to update all collection$unset
to remove the old fields*pipeline update requires MongodDB >= 4.2
updateMany({},
[{"$set": {"languages": ["$language"], "documentIds": ["$documentId"]}},
{"$unset": ["language", "documentId"]}])
Upvotes: 1