我正在尝试在 Django 中使用聚合进行查询,它适用于我的本地计算机,但不适用于服务器。
在两台机器上,pymongo 都安装在 Python 虚拟环境中:
pip freeze | grep mongo
pymongo==2.5.2
我还可以使用 find() 方法在两台机器中获取插入的数据:conn.firmalar.searchlogger.find()
但是聚合方法在我的本地有效,但在服务器中无效,即使安装的所有内容都相同。当我尝试在服务器上运行它时出现此错误:
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