Let's take a collection named values which contains the following documents.
{ "_id" : 1, "name" : "value1", "x" : 1, "y" : 2 }
{ "_id" : 2, "name" : "value1", "x" : 2, "y" : 2 }
{ "_id" : 3, "name" : "value1", "z" : 10 }
{ "_id" : 4, "name" : "value1", "z" : 20 }
{ "_id" : 5, "name" : "value2", "x" : 8, "y" : 3 }
{ "_id" : 6, "name" : "value2", "x" : 8, "y" : 3 }
{ "_id" : 7, "name" : "value2", "z" : 15 }
Here, if I query based on name, take value1, then I should get the following single document.
{ "name" : "value1", "x" : [ 1, 2 ], "y" : [ 2, 2 ], "z" : [ 10, 20 ] }
I think this has something to do with aggregation. But I have no idea how to do it. Is there any way to achieve this behavior?