1

I have a collection Employee and has the following records in it

{
    "id": 1,
    "name": "Scott",
    "company": "Google"
}

{
    "id": 2,
    "name": "Steven",
    "company": "Yahoo"
}

{
    "id": 1,
    "name": "Adam",
    "company": "Facebook"
}

Any suggestions on what kind of mongodb aggregation pipeline has to be used in order to split the data based on the common field id. For the above example, I would be getting two records as my outcome one which contains key as id 1 with the corresponding list of associated values and the other with the key as 2.

user8363477
  • 655
  • 4
  • 14
  • 24
  • You need a $group stage. Please look at the linked dups. Should be `TypedAggregation aggregation = Aggregation.newAggregation(YourPojo.class, Aggregation.group("id"). push("$$ROOT").as("matches"));` – s7vr Jul 16 '18 at 16:08

0 Answers0