Is it possible, in some way, to group upon a field in DocumentDB, stored procedure or not?
Let's say I have the following collection:
[
{
name: "Item A",
priority: 1
},
{
name: "Item B",
priority: 2
},
{
name: "Item C",
priority: 2
},
{
name: "Item D",
priority: 1
}
]
I would like to get all the items in the highest priority group (priority 2 in this case). I do not know what value of the highest priority. I.e.:
[
{
name: "Item B",
priority: 2
},
{
name: "Item C",
priority: 2
}
]
With some crude LINQ, it would look something like this:
var highestPriority =
collection
.GroupBy(x => x.Priority)
.OrderByDescending(x => x.Key)
.First();