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

$ne and $nin do not match docs lacking the searched field

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 0.9.8
    • Affects Version/s: None
    • Component/s: Usability
    • None

      > db.not.insert(

      {a:1}

      )
      > db.not.insert(

      {a:2}

      )
      > db.not.insert({})
      > db.not.find({})

      {"_id" : ObjectId( "4a70d57450cc2b64ff07f162") , "a" : 1} {"_id" : ObjectId( "4a70d57650cc2b64ff07f163") , "a" : 2} {"_id" : ObjectId( "4a70d57850cc2b64ff07f164") }

      > db.not.find(

      {a:1}

      )

      {"_id" : ObjectId( "4a70d57450cc2b64ff07f162") , "a" : 1}

      > db.not.find({a:{$ne:1}})

      {"_id" : ObjectId( "4a70d57650cc2b64ff07f163") , "a" : 2}

      > db.not.find({a:{$in:[1]}})

      {"_id" : ObjectId( "4a70d57450cc2b64ff07f162") , "a" : 1}

      > db.not.find({a:{$nin:[1]}})

      {"_id" : ObjectId( "4a70d57650cc2b64ff07f163") , "a" : 2}

      Note that the empty document is never found. This is surprising if you are expecting $nin to return all docs in the collection not returned by $in (same for $ne and $eq).

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: