c# - Grouping by a field in DocumentDB -
is possible, in way, group upon field in documentdb, stored procedure or not?
let's have following collection:
[ { name: "item a", priority: 1 }, { name: "item b", priority: 2 }, { name: "item c", priority: 2 }, { name: "item d", priority: 1 } ]
i items in highest priority group (priority 2 in case). not know value of highest priority. i.e.:
[ { name: "item b", priority: 2 }, { name: "item c", priority: 2 } ]
with crude linq, this:
var highestpriority = collection .groupby(x => x.priority) .orderbydescending(x => x.key) .first();
documentdb not support group nor other aggregation. second requested feature , listed "under review" on documentdb uservoice.
in mean time, documentdb-lumenize aggregation library documentdb written stored procedure. load cube.string
stored procedure, call aggregation configuration. it's bit overkill example, it's capable of doing asking here. if pass stored procedure:
{cubeconfig: {groupby: "name", field: "priority", f: "max"}}
that should want.
note, lumenize can lot more including simple group-by's other function (sum, count, min, max, median, p75, etc.), pivot tables, , way complicated n-dimensional hypercubes multiple metrics per cell.
i have never tried loading cube.string .net because we're on node.js, shipped string rather javascript can load , send it.
alternatively, write stored procedure simple aggregation.
Comments
Post a Comment