弃用之后的cursor.count()的替代方法

时间:2018-12-27 02:01:23

标签: python python-3.x mongodb pymongo pymongo-3.x

继续进行本讨论:why pymongo count_documents is slower than count

如果我像这样在PyMongo中查询我的MongoDB数据库

cursor = mydb.mycollection.find( {'some_key' : 'some_val'} )

既然cursor.count()将被弃用,如何有效地获取该查询的大小?

一种选择是使用:

mydb.mycollection.count_documents( {'some_key' : 'some_val'} )

但是,这涉及到重新运行查询,据我了解,该查询的效率低于当前解决方案。

0 个答案:

没有答案