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

Negated match with $or not working

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

      Given the documents

      { "status" : "A", "type" : "C" }
      { "status" : "A", "type" : "D" }
      { "status" : "B", "type" : "C" }
      { "status" : "B", "type" : "D" }
      

      Issuing a query like this:

      db.collection.find({
          "$or": [
              { "status": { "$ne": "A" } }, 
              { "type": { "$ne": "C" }},
          ]
      })
      

      Returns all documents, when the expected result would be to exclude the first document.

      Show
      Given the documents { "status" : "A" , "type" : "C" } { "status" : "A" , "type" : "D" } { "status" : "B" , "type" : "C" } { "status" : "B" , "type" : "D" } Issuing a query like this: db.collection.find({ "$or" : [ { "status" : { "$ne" : "A" } }, { "type" : { "$ne" : "C" }}, ] }) Returns all documents, when the expected result would be to exclude the first document.

      There is a different behavior of a given query using inequality matching in combination with $or.

      There is some additional information on consideration of $not as a top level operator in SERVER-14201

            Assignee:
            stephen.steneker@mongodb.com Stennie Steneker (Inactive)
            Reporter:
            neillunn Neil Lunn
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: