G
G
ganjo8882020-11-06 15:09:37
MongoDB
ganjo888, 2020-11-06 15:09:37

How to get the sum of records for each user in mongo?

there is a list of user id = ['63106487-78af-3487-91da-92f380e56e96','ee6bb121-8d63-3c8b-94a0-e917e329f838'

]

{
    "_id": {"$oid": "5f997b922b9f7cc20b223116"},
    "created_at": {"$date": "2020-10-29T11:31:32.915Z"},
    "output_payload": {
      "user_id": {"$binary": 63106487-78af-3487-91da-92f380e56e96}
    }
  },
  {
    "_id": {"$oid": "5f997b922b9f7cc20b223117"},
    "created_at": {"$date": "2020-10-29T11:31:32.919Z"},
    "output_payload": {
      "expert_id": {"$binary": ee6bb121-8d63-3c8b-94a0-e917e329f838}
    }
  },
  {
    "_id": {"$oid": "5f997b922b9f7cc20b223118"},
    "created_at": {"$date": "2020-10-29T11:31:32.923Z"},
    "output_payload": {
      "user_id": {"$binary": ee6bb121-8d63-3c8b-94a0-e917e329f838}
    }
  }


How can I get the sum of entries for each user?
At the output I want to get
ee6bb121-8d63-3c8b-94a0-e917e329f838: 2
63106487-78af-3487-91da-92f380e56e96 : 1

I would be very grateful for your help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Cheremkhin, 2020-11-06
@Che603000

Use aggregation
https://docs.mongodb.com/manual/reference/operator...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question