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

Curious indexing behavior with arrays

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 1.7.6
    • Component/s: Index Maintenance
    • None
    • Environment:
      Linux Ubuntu 64 bit
    • ALL

      Queries can return different results depending on whether an index exists or not, when Indexing on lists.

      It is best illustrated with code:

      > db.test.insert(

      {a:[1,1,1]}

      )
      > db.test.insert(

      {a:[1,1,2]}

      )
      > db.test.insert(

      {a:[1,1,3]}

      )
      > db.test.insert(

      {a:[1,2]}

      )
      > db.test.insert(

      {a:[1,2,1]}

      )
      > db.test.insert(

      {a:[2,1]}

      )
      > db.test.insert(

      {a:[3]}

      )

      > db.test.find(

      {'a.0':1}

      )

      { "_id" : ObjectId("4d60ceef276d207f24f8c3b2"), "a" : [ 1, 1, 1 ] } { "_id" : ObjectId("4d60cef1276d207f24f8c3b3"), "a" : [ 1, 1, 2 ] } { "_id" : ObjectId("4d60cef2276d207f24f8c3b4"), "a" : [ 1, 1, 3 ] } { "_id" : ObjectId("4d60cef9276d207f24f8c3b5"), "a" : [ 1, 2 ] } { "_id" : ObjectId("4d60cf04276d207f24f8c3b6"), "a" : [ 1, 2, 1 ] }

      Unless you add an index:
      > db.test.ensureIndex(

      {'a.0':1}

      )
      > db.test.find(

      {'a.0':1}

      )

      Same query now returns nothing. Returning nothing is probably what is expected in this case.

            Assignee:
            Unassigned Unassigned
            Reporter:
            wladimir W. van der Laan
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: