I have a collection that looks like this:
{'start': '2011-01-29',
'target': [0.0, 2.0],
'cat': [0, 0, 0, 0, 0],
'state': 0},
...
I had to do some aggregations in this collection using db.collections.aggregate([]), and because of performance issues I had to separate into two queries.
The first one returns me:
{'_id': {'state': 0, 'id': 0},
'start': '2011-01-29',
'cat': [0, 0, 0, 0, 0]}
...
The second one returns me:
{'_id': {'state': 0, 'id': 0},
'target': [0, 2, 1]
}
...
What I would like to know, if there is a way to join again the results based on _id?
Or is there a way to declare both query independently into the same one ?
db.collections.aggregate([
query1: {},
query2: {}
concat(query1,query2) ])
My desired output:
Combine again both outputs
{'_id': {'state': 0, 'id': 0},
'start': '2011-01-29',
'cat': [0, 0, 0, 0, 0]}
...
{'_id': {'state': 0, 'id': 0},
'target': [0, 2, 1]
}
...
Into this
{'_id': {'state': 0, 'id': 0},
'start': '2011-01-29',
'target': [0, 2, 1]
'cat': [0, 0, 0, 0, 0]}
...
My solution so far was using pymongo:
x1 = db.collection.aggregate(query1)
x2 = db.collection.aggregate(query2)
for i, j in zip(x1, x2):
j['target'] = i['target']