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

Creating a sparse index makes the not equals query to return diferent results.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 2.4.10
    • Fix Version/s: 2.6.0
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      in python:

      import pymongo
      conn = pymongo.MongoClient()
      db = conn['spare-test']
      col = db['spare-test']
      col.drop()
      col.insert(

      {'_id':0}

      )
      col.insert(

      {'_id':1, 'val':1}

      )
      col.insert(

      {'_id':2, 'val':2}

      )
      col.insert(

      {'_id':3, 'val':3}

      )
      print col.find({'val':{'$ne':2}}).count()
      col.ensure_index([('val',1)], sparse=True)
      print col.find({'val':{'$ne':2}}).count()

      Show
      in python: import pymongo conn = pymongo.MongoClient() db = conn ['spare-test'] col = db ['spare-test'] col.drop() col.insert( {'_id':0} ) col.insert( {'_id':1, 'val':1} ) col.insert( {'_id':2, 'val':2} ) col.insert( {'_id':3, 'val':3} ) print col.find({'val':{'$ne':2}}).count() col.ensure_index( [('val',1)] , sparse=True) print col.find({'val':{'$ne':2}}).count()

      Description

      The documentationhttp://docs.mongodb.org/manual/reference/operator/query/ne/ descrive the '$ne' function as:

      $ne selects the documents where the value of the field is not equal (i.e. !=) to the specified value. This includes documents that do not contain the field.

      However this becames is false when the queried value have an sparse index.

      I can workarround but is a extrange behaivour when you don't expect it.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              hari.khalsa@10gen.com hari.khalsa@10gen.com
              Reporter:
              mabodo David Martin-Borregon
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: