mongodb: field sorted by number of occurances -
i have collection each document representing virtual auction. want find common item id given time period. in sql, i'd select item, count(*) count
group item
, usual sorting , limits. there mongodb equivalent this?
mongodb has several options here.
- in version 2.1.0+ can use new aggregation framework. there's conversion chart right here.
- in older versions can use either map / reduce
- for simple versions of aggregation ca use special aggregation operators.
each of these options have different syntax , different speed.
in of these cases, find these options relatively slow. map / reduce jobs intended run "off-line", "cron job" or "scheduled task". note if plan lot, want pre-aggregate data.
Comments
Post a Comment