Pymongo queries the first 1w of data for a specific condition, and the count result is the number of records of the entire collection. What's wrong with me?

the code is as follows:
recode1 = table_out.find ({}). Sort ([("_ id", 1)]) .limit (10000)
print ("total:", recode1.count ())
directly understand that the number of count () given by print should be 10,000, but what is currently output is the total number of records of the entire collection. Please answer, thank you very much.

Mar.02,2021

The cursor.count () method of

mongo, by default, ignores the effects of cursor.skip () and cursor.limit () , and directly returns the matching results of the find () method. If you need to consider limit, you need to specify the applySkipLimit parameter as true .
in pymongo, this parameter corresponds to the with_limit_and_skip parameter in the method. Don't bother to flip through the documentation. Here are the function definitions extracted directly from the pymongo-cursor.py source code:

  mongo official document: cursor.count () : 

applySkipLimit: boolean
Optional. Specifies whether to consider the effects of the cursor.skip () and cursor.limit () methods in the count. By default, the count () method ignores the effects of the cursor.skip () and cursor.limit (). Set applySkipLimit to true to consider the effect of these methods.
Menu