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

Empty parent returned where projection key doesn't exist

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL
    • Hide

      // Returns immediate parent which exists
      db.test.insert({'level1':{'level2':

      {'key':'value'}

      }})
      db.test.find({},

      {'level1.level2.key2':1,'_id':0}

      )
      Result: { "level1" : { "level2" : { } } }
      Expected: Nothing

      // Returns 2 parents up which exists
      db.test.insert({'level1':{'key':'value'}})
      db.test.find({},

      {'level1.level2.key2':1,'_id':0}

      )
      Result: { "level1" : { } }
      Expected: Nothing

      It should be noted that if there was a projection for keys within the respective docs returned they would be showed. However, I'm not sure why an empty sub doc is returned when no other projections are made for it.

      Is this an intended design or a bug?

      Show
      // Returns immediate parent which exists db.test.insert({'level1':{'level2': {'key':'value'} }}) db.test.find({}, {'level1.level2.key2':1,'_id':0} ) Result: { "level1" : { "level2" : { } } } Expected: Nothing // Returns 2 parents up which exists db.test.insert({'level1':{'key':'value'}}) db.test.find({}, {'level1.level2.key2':1,'_id':0} ) Result: { "level1" : { } } Expected: Nothing It should be noted that if there was a projection for keys within the respective docs returned they would be showed. However, I'm not sure why an empty sub doc is returned when no other projections are made for it. Is this an intended design or a bug?

      When using dot notation to construct a projection on sub document keys, if the key specified in the project doesn't exist it returns the next ancestor which does exist, but as an empty document.

            Assignee:
            stephen.steneker@mongodb.com Stennie Steneker (Inactive)
            Reporter:
            mattcampbell Matt Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: