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

$exists query behaves incorrectly in subdocuments

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

      > db.test.insert({obj:{prop:null}})
      > db.test.findOne()
      {
      "_id" : ObjectId("52298b4aaa95c6f468712074"),
      "obj" :

      { "prop" : null }

      }
      > db.test.findOne({"obj.prop":{$exists: true}})
      {
      "_id" : ObjectId("52298b4aaa95c6f468712074"),
      "obj" :

      { "prop" : null }

      }

      Show
      > db.test.insert({obj:{prop:null}}) > db.test.findOne() { "_id" : ObjectId("52298b4aaa95c6f468712074"), "obj" : { "prop" : null } } > db.test.findOne({"obj.prop":{$exists: true}}) { "_id" : ObjectId("52298b4aaa95c6f468712074"), "obj" : { "prop" : null } }

      According to the documentation[1] "Documents that contain the field but has the value null are not returned."

      This doesn't appear to be true, if one is querying against subdocuments.

      [1] http://docs.mongodb.org/manual/reference/operator/exists/

            Assignee:
            Unassigned Unassigned
            Reporter:
            reezer Christian Sturm
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: