aggregation with pagination

33 views
Skip to first unread message

gD

unread,
Mar 17, 2019, 8:55:29 PM3/17/19
to Eve REST Framework
Hello, 

is it possible to have pagination (_meta) with aggregation ? (see settings.py at the end)


$ curl http://192.168.X.Y:5002/unifi_event/mac?max_results=2 | python -m json.tool

{
    "_items": [
        {
            "_id": "c0:f8:da:a5:bc:8d",
            "count": 2,
            "last_at": "Sat, 16 Mar 2019 14:05:21 GMT"
        },
        {
            "_id": "00:ee:13:00:18:f1",
            "count": 1,
            "last_at": "Sat, 16 Mar 2019 15:59:27 GMT"
        }
    ]
}

but with a "normal query" :

$ curl 2>/dev/null http://192.168.X.Y:5002/unifi_event?max_results=1 | python -m json.tool 

{
    "_items": [
        {
            "MAC": "b4:9c:df:7c:34:23",
            "_created": "Thu, 01 Jan 1970 00:00:00 GMT",
            "_id": "5c7e6f7f2f77d616ba356b5c",
            "_links": {
                "self": {
                    "href": "unifi_event/5c7e6f7f2f77d616ba356b5c",
                    "title": "Unifi_event"
                }
            },
            "_updated": "Thu, 01 Jan 1970 00:00:00 GMT",
            "created_at": "Tue, 05 Mar 2019 12:45:51 GMT"
        }
    ],
    "_links": {
        "last": {
            "href": "unifi_event?max_results=1&page=698",
            "title": "last page"
        },
        "next": {
            "href": "unifi_event?max_results=1&page=2",
            "title": "next page"
        },
        "parent": {
            "href": "/",
            "title": "home"
        },
        "self": {
            "href": "unifi_event?max_results=1",
            "title": "unifi_event"
        }
    },
    "_meta": {
        "max_results": 1,
        "page": 1,
        "total": 698
    }
}




settings.py:

MONGO_HOST = '192.168.3.20'
MONGO_PORT = 27017
MONGO_DBNAME = 'wifi-tracking'
RESOURCE_METHODS = ['GET', 'POST']
ITEM_METHODS = ['GET', 'PATCH', 'DELETE', 'PUT']
IF_MATCH = False
DEBUG = True
PAGINATION = True

unifi_event_mac_count = {
  'url': 'unifi_event/mac',
  'datasource': {
     'source':"unifi_event",
     'aggregation': {
        'pipeline': [
           {"$group": {"_id": "$MAC", "count": {"$sum": 1}, "last_at":{"$max":"$created_at"}}},
        ]
     }
  }
}

unifi_event = {
   'schema': { 
     'MAC': {
        'type': 'string',
        'minlength': 1,
        'maxlength': 17
      },
     'type': {
        'type': 'string'
      },
     'created_at': {
        'type': 'integer'
      },
  }
}


DOMAIN = {"unifi_event_mac_count":unifi_event_mac_count, 'unifi_event':unifi_event,}

Versions (same with issue version 3.6.7 and python 2.6):

$ pip list
Package       Version
------------- -------
Cerberus      1.2    
Click         7.0    
Eve           0.8.1  
Events        0.3    
Flask         1.0.2  
itsdangerous  1.1.0  
Jinja2        2.10  
MarkupSafe    1.1.1  
pip           19.0.3
pkg-resources 0.0.0  
pymongo       3.7.2  
setuptools    40.8.0
simplejson    3.16.0
Werkzeug      0.14.1
wheel         0.33.1

thanks!
Reply all
Reply to author
Forward
0 new messages