Aggregation Group by an array

Hello

Is it possible to group by 3 fields ( in my case name,company, function) ?

For now i can group only by name, this is the current output :
the aggregation :

    group = {"$group": {"_id": "$name", "contacts": {"$push": "$$ROOT"}}}

Output;

{
	"content": [
		{
			"_id": "Name Example 1",
			"contacts": [
				{
					"source": "FANAF2018",
					"name": "Name Example 1",
					"mail": "FANAF@gmail.com",
					"international": "International",
					"function": "test_func1",
					"company": "test_company1",
					"_id": "EB1885A2CAB343788E8B8394C296441D"
				},
				{
					"source": "DSH2329",
					"name": "Name Example 1",
					"mail": "DSH@gmail.com",
					"international": "International",
					"function": "test_func1",
					"company": "test_company1",
					"_id": "79212F41F98C44AF9C91CB482ED226F2"
				}
			]
		},
	...
}

This is what i want to acheive :

{
	"content": [
		{
			"_id": "1234567",
      "name": "Name Example 1",
      "function": "test_func1",
      "company": "test_company1",
			"contacts": [
				{
					"source": "FANAF2018",
					"mail": "FANAF@gmail.com",
					"international": "International",
					"_id": "EB1885A2CAB343788E8B8394C296441D"
				},
				{
					"source": "DSH2329",
					"mail": "DSH@gmail.com",
					"international": "International",
					"_id": "79212F41F98C44AF9C91CB482ED226F2"
				}
			]
		},
	...
}

Thank you

Hi,

Can you add example data, and expected output for that example data?

The groups are based on the _id. To have a group based on multiple fields you need to specify the fields has part of the _id, in your case something like:

{ "$group" : 
  { "_id" :
    {
      "name" : "$name" ,
      "company" : "$company" ,
      "function" : "$function"
    }
  }
}

See related post at How to group on multiple columns and sum up individual columns

Note to documentation team

I tried to find an example from https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/ to share but I could not find one. It certainly would be a good addition. How do we fire an update to documentation?