heynemann / motorengine

Motorengine is a port of MongoEngine for Tornado.
http://motorengine.readthedocs.org
204 stars 67 forks source link

Implement Aggregation #46

Open heynemann opened 10 years ago

heynemann commented 10 years ago

Allow users to aggregate data using the new Aggregation Pipeline(http://docs.mongodb.org/manual/core/aggregation-pipeline/):

class Product(Document):
    type = StringField()
    location = StringField()
    price = FloatField()
    stocked = IntField()
    is_active = BooleanField()

Document.objects.filter(is_active=True).order_by("type").aggregate(
    group_by=[Document.type, Document.location],
    price=Aggregation.add_to_set(Document.price),
    stocked=Aggregation.add_to_set(Document.stocked)
)

The types of aggregation are in the following tickets: