Skip to content

Instantly share code, notes, and snippets.

@johnantoni
Created October 23, 2012 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnantoni/3939298 to your computer and use it in GitHub Desktop.
Save johnantoni/3939298 to your computer and use it in GitHub Desktop.
mongoid group by
products.collection.group(:key => 'family', :initial => {count: 0}, :reduce => "function(doc,prev) { prev.count += +1; }")
products.collection.group(:keyf => 'function(doc) { return {family: doc.family};}', :initial => {count: 0}, :reduce => "function(doc,prev) { prev.count += +1; }", :finalize => 'function(doc) { doc; }')
@andreimerlescu
Copy link

pardon my french here but why the fuck does mongo syntax query look like hell on earth?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment