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

    XMLWordPrintable

    Details

    • Type: Question
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 4.2.9
    • Fix Version/s: Backlog
    • Component/s: Indexing, Querying
    • Labels:
      None
    • Sprint:
      Execution Team 2020-11-16, Execution Team 2020-12-14

      Description

      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?

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated: