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

Curious indexing behavior with arrays

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Duplicate
    • Affects Version/s: 1.7.6
    • Fix Version/s: None
    • Component/s: Indexing
    • Labels:
      None
    • Environment:
      Linux Ubuntu 64 bit
    • Operating System:
      ALL

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: