擅长:python、mysql、java
<p>从<code>Mongo 4.0.3</code>/<code>PyMongo 3.7.0</code>开始,您可以选择在<code>cursor</code>上使用<a href="https://api.mongodb.com/python/3.7.2/api/pymongo/collection.html?highlight=count#pymongo.collection.Collection.count_documents" rel="nofollow noreferrer">^{<cd3>}</a>,而不是<code>count</code>:</p>
<pre><code>db.collection.count_documents({ "a": 2 })
# where { "a": 2 } is whatever filtering query
</code></pre>
<p><code>db.collection.count_documents</code>是现在已弃用的<a href="https://api.mongodb.com/python/3.7.2/api/pymongo/collection.html?highlight=count#pymongo.collection.Collection.count" rel="nofollow noreferrer">^{<cd7>}</a>的替代方案。</p>