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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • 0.9.8
    • Affects Version/s: None
    • Component/s: Usability
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • 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 Horowitz (Inactive)
            Reporter:
            Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: