mongoid / origin

A Ruby DSL for building MongoDB queries
http://mongoid.org/en/origin/index.html
MIT License
62 stars 29 forks source link

Add Pipeline DSL for Aggregations #24

Closed durran closed 11 years ago

durran commented 12 years ago

See docs, need to flush out API in Origin.

http://www.mongodb.org/display/DOCS/Aggregation+Framework http://www.mongodb.org/display/DOCS/Aggregation+Framework+-+Expression+Reference

rodrigosaito commented 11 years ago

I will be working on it... any considerations?

durran commented 11 years ago

This one will be a bit more tricky since it's a full blown DSL around it. I'm open to suggestions but before you go doing any amount of significant work on this one please run the ideas by me first. :)

durran commented 11 years ago

I will also think about this some more this weekend and come up with some ideas for you as well. Appreciate you spearheading the aggregation framework efforts. :)

rodrigosaito commented 11 years ago

Just trying to improve my ruby skills and mongoid/moped/origin are really great projects to work on.... well designed... both code and tests.....

rodrigosaito commented 11 years ago

The aggregate operation is always executed over a collection, so I am not sure where we should start the DSL.

If we include something like Origin:Aggregatable on Origin::Queryable the user will be able to mix query selectors with aggregation operators, this could be a good idea if we consider that the selector will become a $match operator. But the user will be able to mix things and may end up with something not readable.

I am thinking on something like this for the dsl:

criteria = Criteria.new

criteria.project(author : true, tags : true)
  .unwind(:tags)
  .group(_id: { tags: true }, authors: { addToSet: :author})

Which will be translated to:

  { $project : {
     author : 1,
     tags : 1,
  } },
  { $unwind : "$tags" },
  { $group : {
     _id : { tags : 1 },
     authors : { $addToSet : "$author" }
  } }

@durran Please, give your considerations or your ideas about this.

abrisse commented 11 years ago

Any update about this ?

durran commented 11 years ago

Finished on master.