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

adding an index returns different results when their is an empty array

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.2
    • Affects Version/s: 1.6.2
    • Component/s: Index Maintenance
    • Labels:
      None
    • ALL

      Problem:
      A different number of documents are returned if an array is indexed or not.

      Reproduce:

      > db.perm.save(

      { what : "1", permissions : [ "perm-access-help" ] }

      )
      > db.perm.save(

      { what : "2", permissions : [ "perm-access-admin-area" ] }

      )
      > db.perm.save(

      { what : "3", permissions : [ "perm-access-admin-area","perm-access-help" ] }

      )
      > db.perm.save(

      { what : "4", permissions : [ ] }

      )
      > db.perm.save(

      { what : "5" }

      )

      Query with out the index, returns four documents
      > db.perm.find( { permissions :

      { $in:["perm-access-help", "perm-access-admin-area", null] }

      } )

      { "_id" : ObjectId("4cb64a7540292d4539c3ceeb"), "what" : "1", "permissions" : [ "perm-access-help" ] } { "_id" : ObjectId("4cb64a8040292d4539c3ceec"), "what" : "2", "permissions" : [ "perm-access-admin-area" ] } { "_id" : ObjectId("4cb64a8b40292d4539c3ceed"), "what" : "3", "permissions" : [ "perm-access-admin-area", "perm-access-help" ] } { "_id" : ObjectId("4cb64aa140292d4539c3ceef"), "what" : "5" }

      Adding the index returns 5 documents
      > db.perm.ensureIndex(

      {permissions : 1}

      )
      > db.perm.find( { permissions :

      { $in:["perm-access-help", "perm-access-admin-area", null] }

      } )

      { "_id" : ObjectId("4cb64a9940292d4539c3ceee"), "what" : "4", "permissions" : [ ] } { "_id" : ObjectId("4cb64aa140292d4539c3ceef"), "what" : "5" } { "_id" : ObjectId("4cb64a8040292d4539c3ceec"), "what" : "2", "permissions" : [ "perm-access-admin-area" ] } { "_id" : ObjectId("4cb64a8b40292d4539c3ceed"), "what" : "3", "permissions" : [ "perm-access-admin-area", "perm-access-help" ] } { "_id" : ObjectId("4cb64a7540292d4539c3ceeb"), "what" : "1", "permissions" : [ "perm-access-help" ] }

      Business Case:

      • reliability
        The behavior of the query should not change depending on whether an index is present or not.

            Assignee:
            aaron Aaron Staple
            Reporter:
            alvin Alvin Richards (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: