python - How to merge two aggregation queries into one -


how can merge these 2 queries one:

query 1

db.response.aggregate([      {         "$and": [             { "job_details.owner_id" : 428 },             { "job_details.owner_type" : 'searches' }         ]     },     {         "$group": {             "_id": "$candidate_city_name_string",             "count": { "$sum": 1 }         }     } ]) 

query 2

db.response.aggregate([      {         "$and": [             { "job_details.owner_id" : 428 },             { "job_details.owner_type" : 'searches' }         ]     },     {         "$group": {             "_id": "$skill",             "count": { "$sum": 1 }         }     } ]) 

the result of query output 1:

{     "result": [         { _id: 'bangalore', count: 8 },         { _id: 'cochi', count: 9 }     ]     "ok":1 } 

output 2:

{     "result": [         { _id: 'java', count: 7 },         { _id: 'python', count: 10 }     ],     "ok":1 } 

how can these 2 results in 1 query?

i need output this:

expected output:

 {      "result": [          "candidate_city_name_string": [              { _id: 'bangalore', count: 8 },              { _id: 'cochi', count: 9 }          ],          "skill": [              { _id: 'java', count: 7 },              { _id: 'python', count: 10 }          ]        ],      "ok":1  } 

is possible? somewhere saw $facet didn't understand that.

db.response.aggregate([ {"$match":{"$and":[{"job_details.owner_id" : 482},{"job_details.owner_type" : 'searches'}]}},  {$facet: {     "candidate_sublocation_name_string": [                          {"$group": {"_id":"$candidate_sublocation_name_string","count": {"$sum": 1 }}}                       ],     "skill": [                          {"$group": {"_id":"$skill","count": {"$sum": 1 }}}                       ]         }}]) 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -