Search code examples
pythonmongodbpymongoevemongodb-aggregation

Python EVE aggregation not working


I am using Eve to create a RESTful API for MongoDB. Maybe I am doing something wrong, but I cant figure out why Eve is not returning me aggregated results. Below is my DOMAIN:

DOMAIN = {
    'heartbeats': {
        'schema': {
            'user': {
                'type': 'objectid',
                'required': True,
            },
            'device': {
                'type': 'objectid',
                'required': True,
            },
            'pir': {
                'type': 'integer'
            },
            'camera': {
                'type': 'integer'
            },
            'image': {
                'type': 'media',
                'required':False
            }
        }
    },
    'chart1' : {
        'datasource':{
            'source' : 'heartbeats',
            'aggregation' : {
                'pipeline': [
                    {"$group" : {"_id":"$user", "count" : {"$sum" : 1}}}
                ]
            }
        }
    }
}

And when querying it from browser I get just all the records, not aggregated results.

enter image description here

Why am I not getting aggregated results??


Solution

  • On which Eve version are you? MongoDB Aggregation Framework support is currently on the development branch. If you are using any of the stable versions (v0.6.4 being the latest), you won't get aggregation support. Try installing the development branch.