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

$in doesn't find fields of type undef as null

    XMLWordPrintable

    Details

    • Operating System:
      ALL

      Description

      If you have a values which is undefined versus null - $in doesnt work

       
      db.a.insert({x:1,v:null})
      db.a.insert({x:2,v:""})
      db.a.insert({x:3})
      db.a.insert({x:4,v:undefined})
       
      db.a.find(v:null)
      

      Finds all except wher v is ""
      but

      db.a.find(v:{$in:[null,""]})
      

      fails to find the record where x = 4

      A workaround is

      db.u.find({ $or : [ {v:{$type:6}},{v:{$in:[null,""]}}]})
      

      Which is ugly

        Attachments

          Activity

            People

            Assignee:
            backlog-query-optimization Backlog - Query Optimization
            Reporter:
            john.page John Page
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: