cem-
cem-

Reputation: 93

Mongo aggregation doesn't work in pymongo

I am trying to make a query with aggregate in Django, it works fine with my local computer but not in the server.

In both machines, pymongo is installed in Python virtual enviroment:

pip freeze | grep mongo
pymongo==2.5.2

I can also get the inserted data in two machines with find() method: conn.firmalar.searchlogger.find()

But aggregate method works in my local but not in the server even everything installed are the same. I got this error when i attempt to run it on server:

import pymongo
conn = pymongo.Connection()
search = conn.firmalar.searchlogger.aggregate([{"$group": {"_id": "$what", "count": {"$sum": 1}}}])

    OperationFailure at /admin/weblog/
command SON([('aggregate', u'searchlogger'), ('pipeline', [{'$group': {'count': {'$sum': 1}, '_id': '$what'}}])]) failed: no such cmd: aggregate

    /home/cem/env/firmalar/local/lib/python2.7/site-packages/pymongo/collection.pyc in aggregate(self, pipeline)
   1059                                          self.secondary_acceptable_latency_ms),
   1060                                         slave_okay=self.slave_okay,
-> 1061                                         _use_master=use_master)
   1062 
   1063     # TODO key and condition ought to be optional, but deprecation


/home/cem/env/firmalar/local/lib/python2.7/site-packages/pymongo/helpers.pyc in _check_command_response(response, reset, msg, allowable_errors)
    145             if code in (11000, 11001, 12582):
    146                 raise DuplicateKeyError(errmsg, code)
--> 147             raise OperationFailure(msg % errmsg, code)
    148 
    149 

Upvotes: 1

Views: 1485

Answers (1)

alecxe
alecxe

Reputation: 474271

It's not about the driver - it's about mongodb itself. aggregate() was introduced in mongodb 2.2: docs.

Most likely, you are using an older version of mongodb. Check your mongodb version and upgrade if needed. Also check that in your python code you are connecting to the mongodb version >=2.2.

Also see:

Upvotes: 3

Related Questions