How to update a collection based on another collection in MongoDB?
- by Sean Zhu
Now I get two collections: coll01 and coll02.
And the structure of coll01 is like this:
{
id: 01,
name: "xxx",
age: 30
}
and the structure of coll02 is like:
{
id: 01,
name: "XYZ"
gender: "male"
}
The two id fields in the both collection are indices. And the numbers of documents in these two collections are same.
And what I want to do in traditional SQL is :
update coll01, coll02
set coll01.name = coll02.name
where coll01.id = coll02.id