0

I have Documents like

{"title":"title_1","website":"website_1","isEdited":"true"},
{"title":"title_2","website":"website_1","isEdited":"true"},
{"title":"title_3","website":"website_2"},
{"title":"title_4","website":"website_3","isEdited":"false"}

so documents have "isEdited" field with multiple values (None , true, flase) i want to count all occurrences of them and group them in like

{'_id' : '$website','edited_count': '?', 'not_edited_count': '?'}

instead of above I am able to get this

{u'isEditedCount': 2, u'_id': u'website_1'}

with this pipeline

[
  {"$match": {"isEdited": 'true'}},
  {"$group": {"_id": "$website", "isEditedCount": {"$sum": 1}}}
]

And [ {u'isNotEditedCount': 1, u'_id': u'website_2'}, {u'isNotEditedCount': 1, u'_id': u'website_3'} ]

with this pipeline

[
  {"$match":{"$or":[{"isEdited": None},{"isEdited": 'false'}]}},
  {"$group":{"_id": "$website","isNotEditedCount": {"$sum": 1}}}
]

I want to combine both pipelines in one

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Tony Stark
  • 35
  • 1
  • 8
  • @neil maybe this is duplicate but as you can see i have a field with three distinct value and i want the count of them in two fields in single pipeline. – Tony Stark May 26 '18 at 08:16
  • So you were pointed to answers using `$cond` and `$ifNull` on evaluation, and yet you have not attempted any of that in your code. Seems you have not actually looked at what actually answers your question. – Neil Lunn May 26 '18 at 08:24

0 Answers0