命令游标“对象不可下载 [英] command cursor' object is not subscriptable
问题描述
aggregate()
函数返回数据时,它给了我以下错误:$ b
command cursor'object is not subcriptable。
这是我查询的代码:
Data = db.mytable.aggregate([{$ group:{_id:$ Name,count:{$ sum :1}}}])
return Data ['result']
我也改变了这个:
$ p $ Data = db.mytable.aggregate([{$ group:{_id:$ Name ,count:{$ sum:1}}}],userCursor = False)
但是它给了我以下错误:
lockquote
error.pymongo.errors.OperationFailure命令SON([('aggregate','mytable ''),('pipeline',[{'$ group':{'_id':'$ Name','count':{'$ sum':1}}}]),('useCursor',False)] )$ cmd失败:无法识别的字段'useCursor
注意:我正在使用MongoDB 3.2和Python3
由于Pymongo 3.0, .aggregate()
方法返回一个 CommandCursor 没有实现 __ getitem __()
方法。相反,我建议你在函数/方法中返回游标
对象,或者将结果转换成如下所示的列表: return list(Data)
I'm new in Python and MongoDB and I am starting a new project with flask-python and MongoDB. When I try returning data using the aggregate()
function, it gives me the following error:
command cursor' object is not subscriptable.
Here is my code for the query:
Data = db.mytable.aggregate([ { "$group": {"_id": "$Name" ,"count": { "$sum": 1 }}}])
return Data['result']
I also changed this:
Data = db.mytable.aggregate([ { "$group": {"_id": "$Name" ,"count": { "$sum": 1 }}}],userCursor= False)
but it gives me the following error:
error.pymongo.errors.OperationFailure: command SON([('aggregate', 'mytable'), ('pipeline', [{'$group': {'_id': '$Name', 'count': {'$sum': 1}}}]), ('useCursor', False)]) on namespace mydb.$cmd failed: unrecognized field 'useCursor
Note: I am using MongoDB 3.2 and Python3
Since Pymongo 3.0, the .aggregate()
method return a CommandCursor which doesn't implement the __getitem__()
method. Instead I suggest you return the cursor
object in your function/method or turn to result into a list like this: return list(Data)
这篇关于命令游标“对象不可下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!