-
Type: Question
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.2.9
-
Component/s: Index Maintenance, Querying
-
None
-
Execution Team 2020-11-16, Execution Team 2020-12-14, Execution Team 2020-12-28, Execution Team 2021-01-11, Execution Team 2021-01-25
According to https://docs.mongodb.com/manual/reference/bson-type-comparison-order/#objects, embedded objects/documents are compared, first, by field names, second, by field values.
Consider a collection:
{_id: 1, tag: {bab: 123}} {_id: 2, tag: {bar: "BAR"}} {_id: 3, tag: {baz: "BAZ"}}
and a query:
{tag: {$gte: {baz: MinKey()}}}
I thought this would return ONLY doc 3 (since `bab` and `bar` are less than `baz`), but it returns ALL three docs. Changing the query to
{tag: {$gte: {baz: ""}}}
returns ONLY doc 3, as I hoped.
Is this an issue? Are range queries supported on whole embedded objects values? Do MinKey and MaxKey have some weird behavior in queries embedded documents?
- is duplicated by
-
SERVER-51383 bsonWoCompare on embedded documents/objects does not match ordering described in documentation
- Closed