1

I had one big collection which is now seprated/divided into 2 collections. And now I would like to retrieve the documents from both of them through a single mongo query.

The only solution I can think of as of now is to write 2 query on those 2 collections seprately and then merge the result at the application level!

I want to achieve this on the db layer itself because the number of documents that I have after combining both the collections is beyond 1 million!!

Ex:

CollectionA: {field_1: "abc", field_2: "xyz", field_3: "abcxyz"},
             {field_1: "def", field_2: "ghi", field_3: "defghi"}

CollectionB: {field_1: "qwe", field_2: "rty", field_3: "qwerty"}

    Result: {field_1: "abc", field_2: "xyz", field_3: "abcxyz"},
            {field_1: "def", field_2: "ghi", field_3: "defghi"},
            {field_1: "qwe", field_2: "rty", field_3: "qwerty"}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • Possible duplicate https://stackoverflow.com/questions/5681851/mongodb-combine-data-from-multiple-collections-into-one-how – chridam Aug 31 '18 at 08:34
  • You can do something like this in mongodb 3.6 and above https://stackoverflow.com/questions/20056903/search-on-multiple-collections-in-mongodb/51348446#51348446 – Ashh Aug 31 '18 at 08:47

0 Answers0