问:是否有 Pymongo `cursor.count()` 的等效替代品? (3.7 -> 3.11)

Q: Is there an equivalent replacement to Pymongo `cursor.count()`? (3.7 -> 3.11)

我希望从 Pymongo 3.7 升级到 3.11 并且 运行 遇到替换弃用函数 cursor.count() 的问题。我需要知道查询返回的文档数。

是否有另一种方法可以计算查询返回的文档数?

count_documents 是通过构建聚合管道并使用 $count 阶段的驱动程序实现的。无法将此计数“附加”到游标或查找查询。

您可能需要重新构建应用程序以将条件传递给 count_documents