I am trying to figure out a way to update multiple documents in a collection with different values based on a key.
persons collection:
{
_id: 1,
name: "Jackie Chan",
Country: Australia
},
{
_id: 2,
name: "Brad Pitt",
Country: Russia
},
{
_id: 3,
name: "Al Pacino",
Country: USA
}
Payload:
{
_id: 1,
name:"Jackie Chan",
Country:"China"
}
,{
_id: 2,
name:"Brad Pitt",
Country:"USA"
}
persons collection after update:
{
_id: 1,
name: "Jackie Chan",
Country: "China"
},
{
_id: 2,
name: "Brad Pitt",
Country: "USA"
},
{
_id: 3,
name: "Al Pacino",
Country: "USA"
}
SQL equivalent would be :
update t1.country = t2.country from persons t1 inner join #temptable t2 on t1._id=t2._id
None of the examples mentioned here explain how to do it. Unless I am missing something?
Brat Pitt/Russia+Brad Pitt/USA=Brad Pitt/China.{ updateOne :{}}withinbulkWrite(). As many times as there are records to be updated ?