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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor - P4 Minor - P4
    • None
    • 3.2.4
    • Querying
    • Query
    • ALL
    • 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

        Activity

          People

            backlog-server-query Backlog - Query Team (Inactive)
            grabekm90 Mateusz Grabowski
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: