Let's say I have the following records:
{ id: 1, value : 1, Date: 2016-01-01 }, { id: 1, value : 2, Date: 2016-01-01 }, { id: 2, value : 3, Date: 2016-01-01 }, { id: 3, value : 4, Date: 2016-01-01 } In mongodb C# driver how would I call a collection with this data format to produce something like:
{ { id: 1, records : [ {value : 1, Date: 2016-01-01}, {value : 2, Date: 2016-01-01} ]}, { id : 2, records : [{value : 3, Date: 2016-01-01}] }, { id : 3, records : [{value : 4, Date: 2016-01-01}] } } So i want to group on the "id" field and then return all results grouped by their id as a list. So the structure would be something like C#'s
Dictionary<int, List<MyObj>>
$grouppipeline operator, where you can group the documents by theidkey and create therecordsarray using the$pushoperator.