这不是一个重复的问题另一个问题与 Mongo 2.6 有关,它确实与 Mongo 2.4 有很大不同。我已经阅读了另一个问题,甚至在这个问题的最后一段中也提到了它。
首先,我对 Mongo 很陌生,甚至对 PyMongo 也很陌生。我正在使用现有脚本并尝试调试它为什么不能在本地运行。以下查询导致错误。
询问:
[{
u'$match': {
u'geocode.co_iso2': u'US',
u'brand._id': UUID('xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
}
},
{
u'$group': {
u'_id': u'$brand._id',
u'num': {u'$sum': 1}
}
},
{
u'$sort': {u'num': -1}
},
{
u'$limit': 100000
}]
代码:
cursor = yield db[collection].aggregate(bsonQuery)
self.write(bson.json_util.dumps(cursor))
错误:
Exception: <class 'tornado.gen.BadYieldError'>:yielded unknown object MotorAggregationCursor(<motor.core._LatentCursor object at 0x10a897b50>)
我还想指出,这是 Mongo 2.4 和 PyMongo 2.8。我知道一些有类似错误的人被告知要在cursor
没有的情况下存储yield
,然后执行while(yield...)
. 试过了,似乎不适用于 Mongo 2.4。它说:
Exception: <class 'pymongo.errors.OperationFailure'>:command SON([('aggregate', u'MyCollection'), ('pipeline', [{u'$match': {u'geocode.co_iso2': u'US', u'brand._id': UUID('xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')}}, {u'$group': {u'_id': u'$brand._id', u'num': {u'$sum': 1}}}, {u'$sort': {u'num': -1}}, {u'$limit': 100000}]), (u'cursor', {})]) on namespace mydatabase.$cmd failed: unrecognized field "cursor