|
Hi ych.tiger@gmail.com,
Thanks for reporting this ticket. It looks to me like this is the expected behavior of the system, so I am closing as "Works as Designed". Please read on for a more detailed description of why this is the expected behavior.
The MongoDB query language semantics include a concept called "type bracketing". This means that when you issue a range predicate with a particular canonical type, the predicate will only match values up to the minimum or maximum value for that type. (Canonical type differs from BSON type; numbers can have BSON type NumberLong, NumberInt, or NumberDouble, but all three have the canonical type of "number".) This means that the predicate {_id: {$gt: "2"}} corresponds to the range ("2", {}). The upper end of this range is an empty nested object ("{}"), which is the first non-string value that compares higher than any string. Since the upper bound is exclusive, the range effectively means "all strings greater than '2'". Documents in which the '_id' field is not a string will not match this query. This is why your query only returns documents with _id "20" and "3".
I performed a quick search of our documentation and did not find any good documentation on type bracketing. Therefore, I filed a ticket on your behalf requesting this documentation: see DOCS-7044.
Please let me know if you have any further questions.
Best,
Dave
|