0

I have two mongodb collections, 'collection1' and 'collection2' and I need one pymongo cursor with both of their results as follows:

the cursor for collection1 gets:

{"month" : "june", "day" : 22}
{"month" : "april", "day" : 3}

the cursor for collection2 gets:

{"month" : "january", "day" : 1}

the cursor I need gets:

{"month" : "june", "day" : 22}
{"month" : "april", "day" : 3}
{"month" : "january", "day" : 1}

So, as you can see, it's not a join, or merge or map reduce, it is simple getting both results as one (I don't even know the name for that). But the result must be a proper pymongo cursor. Any help would be appreciated.

  • What do you mean by "collection1" and "collection2"? If the data is in separate collections then it most likely should not be. In a SQL RDBMS you separate "tables" because they have different structures. MongoDB has no such restriction, so if that is your reasoning then you're doing it wrong. Most likely the data belongs in one collection. No such thing as a UNION here. – Neil Lunn Jun 07 '18 at 04:55
  • @NeilLunn They are not exactly the same, I putted them like that for simplification. I need to merge them for processing but keep them separate for memory issues. I need help with exactly the problem I described, not the motives. Thanks anyway. – Viktor Dunslow Jun 07 '18 at 05:06
  • What I just told you is with "two collections" there is no other way but to essentially process them "separately". There is no such thing as a UNION join. If you have results from "two collections" you need to refactor to make "one collection". That's how MongoDB works. If there was a different answer then you would already have it. – Neil Lunn Jun 07 '18 at 05:08

0 Answers0