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

Document field is empty when a subkey is after the parent key in projection

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Duplicate
    • Affects Version/s: 3.2.4
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      Initiate test collection

      db.test.insert({'contact': {'phone': {'number': 7}}})
      db.test.insert({'contact': {'phone': {'extension': 42}}}
      

      Query test collection

      db.test.find({}, {'contact.phone': 1, 'contact.phone.extension': 1})
      db.test.find({}, {'contact.phone': 1, 'contact.phone.extension': 1})
      

      Show
      Initiate test collection db.test.insert({'contact': {'phone': {'number': 7}}}) db.test.insert({'contact': {'phone': {'extension': 42}}} Query test collection db.test.find({}, {'contact.phone': 1, 'contact.phone.extension': 1}) db.test.find({}, {'contact.phone': 1, 'contact.phone.extension': 1})

      Description

      I generate projection parameters for my mongo queries, depends on a user choice.
      I've noticed an unexpected behavior when I try getting some field (contact.phone) and subfield of the same field (contact.phone.extension). Content of the results depends on the order of projection.
      The bug occours when a subkey is after the parent key in projection. The data under the parent key is missing.

      Query A

      > db.test.find({}, {'contact.phone': 1, 'contact.phone.extension': 1})
      { "_id" : ObjectId("56f157913e5215b0b37b1dfd"), "contact" : { "phone" : { "extension" : 42 } } }
      { "_id" : ObjectId("56f157b33e5215b0b37b1dfe"), "contact" : { "phone" : {  } } }
      

      Query B

      db.test.find({}, {'contact.phone.extension': 1, 'contact.phone': 1})
      { "_id" : ObjectId("56f157913e5215b0b37b1dfd"), "contact" : { "phone" : { "extension" : 42 } } }
      { "_id" : ObjectId("56f157b33e5215b0b37b1dfe"), "contact" : { "phone" : { "number" : 7 } } }
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: