MongoDB: Combine data from multiple collections into one..how?

后端 未结 11 1148
余生分开走
余生分开走 2020-11-22 06:44

How can I (in MongoDB) combine data from multiple collections into one collection?

Can I use map-reduce and if so then how?

I would greatly appreciate some

11条回答
  •  北海茫月
    2020-11-22 07:35

    Mongorestore has this feature of appending on top of whatever is already in the database, so this behavior could be used for combining two collections:

    1. mongodump collection1
    2. collection2.rename(collection1)
    3. mongorestore

    Didn't try it yet, but it might perform faster than the map/reduce approach.

提交回复
热议问题