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

Parsing {$ne: X} to {$not: {$eq: X}} is weird with arrays

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Query Language
    • Labels:
      None

      Description

      > db.blah.insert({a: 'not 3'})
      WriteResult({ "nInserted" : 1 })
      > db.blah.insert({a: ['not 3', 3]})
      WriteResult({ "nInserted" : 1 })
      > db.blah.find({a: {$ne: 3}})
      { "_id" : ObjectId("60634e127cc9a947848c101a"), "a" : "not 3" }
      

      Under the normal rules for arrays, both documents should match, since they each have at least one element in a that matches. However because we convert
      {a: {$ne: X
      }} to {$not: {a: {$eq: X}}} at parse time, we get the observed semantics. If people actually want that behavior, they could always type that directly.

      Might not be able to fix this in MQL1.0, but probably worth keeping this in a list of things to fix for MQL2.0.

        Attachments

          Activity

            People

            Assignee:
            backlog-query-optimization Backlog - Query Optimization
            Reporter:
            redbeard0531 Mathias Stearn
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: