MongoDB replace all matching documents

Viewed 29

If I have a collection like this:

[
   {
     "name":"name1,
     "type":"type1"
   },
   {"name":"name2",
     "type":"type1"
   }
   {
     "name":"name3",
     "type":"type3"
   }
]

And I want to replace all of type1 with a list of entries in one atomic operation

[{
   "name":"name5"
   "type":"type1"
}]

End result would be

[
   {
     "name":"name5",
     "type":"type1"
   }
   {
     "name":"name3",
     "type":"type3"
   }
]

How can I achieve this? Putting them in a common list complicates things, but maybe its the only way?

0 Answers
Related