TypeError:"Cursor"类型的对象没有len() [英] TypeError: object of type 'Cursor' has no len()
本文介绍了TypeError:"Cursor"类型的对象没有len()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此错误:
TypeError:类型为"Cursor"的对象没有len()
TypeError: object of type 'Cursor' has no len()
当我尝试执行时:
reply = db['test'].find({"date":{"$gt":date_query}} ,{"date":1,"route_id":1,"loc":1,"_id":0})
length = len(reply)
推荐答案
pymongo cursor 具有方法 count()
,该方法将返回您要查找的内容:
The pymongo cursor has a method count()
which will return what you're looking for:
reply = db['test'].find(
{"date":{"$gt":date_query}},
{"date":1,"route_id":1,"loc":1,"_id":0}
)
length = reply.count()
这篇关于TypeError:"Cursor"类型的对象没有len()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文