How to update a collection based on another collection in MongoDB?
Posted
by
Sean Zhu
on Stack Overflow
See other posts from Stack Overflow
or by Sean Zhu
Published on 2013-11-06T21:10:05Z
Indexed on
2013/11/06
21:54 UTC
Read the original article
Hit count: 282
mongodb
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
© Stack Overflow or respective owner