In general, the count command treats a limit of -n as identical to a limit of n:
> db.runCommand({count: "c"}) { "n" : 11, "ok" : 1 } > db.runCommand({count: "c", limit: -10}) { "n" : 10, "ok" : 1 }
This is implemented by taking the absolute value of a long long. Taking the absolute value is incorrect for the smallest negative long long, since its absolute value is too large to be represented with 64 signed bits. Consequently, the count command returns an incorrect result when the limit is -2^63:
> db.runCommand({count: "c", limit: NumberLong(-9223372036854775808)}) { "n" : NumberLong("-9223372036854775808"), "ok" : 1 }
This bug affects 4.0, and probably older branches (but I only confirmed on 4.0). It was fixed in 4.1 development by f0b39d91840 under SERVER-37446.
- is related to
-
SERVER-37446 Make remaining collection access stages check collection UUID on yield recovery
- Closed