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.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.6.0
    • Affects Version/s: 2.4.10
    • Component/s: Querying
    • None
    • ALL
    • 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()

      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.

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

              Created:
              Updated:
              Resolved: