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

v0 indexes store empty arrays as nulls and the documents containing them may be improperly returned or counted when the matcher is bypassed

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • ALL

      Has been fixed in v1 indexes. Mostly creating a ticket for this so we can track the issue if reported by users.

      Here is the problem for v0 indexes:

      > c.drop()
      true
      > c.ensureIndex(

      {a:1}

      ,

      {v:0}

      )
      > c.save(

      {a:[]}

      )
      > c.find(

      {a:null}

      ) // key matching only

      { "_id" : ObjectId("4ee8f8d00cf334c01d36adc3"), "a" : [ ] }

      > c.find(

      {a:null,b:null}

      ) // match full doc - [] not matching null
      > c.count(

      {a:null}

      ) // fast count bypasses matcher
      1
      > c.save(

      {a:[1,2]}

      ) // make the index multikey
      > c.find(

      {a:null}

      ) // key matching does not occur for multikey indexes, so match full doc
      > c.find(

      {a:null,b:null}

      ) // match full doc
      > c.count(

      {a:null}

      ) // fast count bypasses matcher
      1

      We've fixed it for v1 indexes:

      > c.drop()
      true
      > c.ensureIndex(

      {a:1}

      )
      > c.save(

      {a:[]}

      )
      > c.find(

      {a:null}

      )
      > c.find(

      {a:null,b:null}

      )
      > c.count(

      {a:null}

      )
      0
      > c.save(

      {a:[1,2]}

      )
      > c.find(

      {a:null}

      )
      > c.find(

      {a:null,b:null}

      )
      > c.count(

      {a:null}

      )
      0
      >

            Assignee:
            Unassigned Unassigned
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: