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

后端 未结 11 1263
余生分开走
余生分开走 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:23

    Yes you can: Take this utility function that I have written today:

    function shangMergeCol() {
      tcol= db.getCollection(arguments[0]);
      for (var i=1; i

    You can pass to this function any number of collections, the first one is going to be the target one. All the rest collections are sources to be transferred to the target one.

提交回复
热议问题