4

I'm just staring out with MongoDB and I'm staring an application with flask-mongoengine and I want to aggregate a few documents.

I'm using flask-mongoengine and when trying

class MyDocumentModel(db.Document):
  name = db.StringField(max_length=55)

MyDocumentModel.objects.aggregate()

I get the error:

AttributeError: 'BaseQuerySet' object has no attribute 'aggregate'

codegeek
  • 32,236
  • 12
  • 63
  • 63
Joelbitar
  • 3,520
  • 4
  • 28
  • 29
  • Can you clarify how you want aggregate documents? Probably you need aggregation methods: https://mongoengine-odm.readthedocs.org/en/latest/guide/querying.html#aggregation. – tbicr Nov 13 '13 at 13:40
  • 1
    You need to use raw pymongo and aggregate functionality. – Asya Kamsky Nov 24 '13 at 21:14

1 Answers1

2

Starting with mongoengine v0.9 (which is currently in development), you will be able to use aggregate(), like you suggested: http://docs.mongoengine.org/apireference.html#mongoengine.queryset.QuerySet.aggregate

Until then, you need to rely on pymongo: Flask-MongoEngine & PyMongo Aggregation Query

nofinator
  • 2,906
  • 21
  • 25