Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-51258

Unexpected behavior in range query on whole embedded documents with MinKey and MaxKey subfield values

    • Type: Icon: Question Question
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 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?

            Assignee:
            geert.bosch@mongodb.com Geert Bosch
            Reporter:
            crunk1@gmail.com Scott Crunkleton
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: