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

planCacheSetFilter doesn't work for queries emitted by pymongo to MongoDB 2.6 if projection is not empty

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL

      I know that MongoDB 2.6 is quite an old version, and the issue is not present in the newest MongoDB 3.2, but I can't switch to MongoDB 3.2 easily. I wonder if there is any workaround?
      The following script exposes the problem:

      #!/bin/bash
      
      DB="test"
      
      mongo <<__EOF
      use $DB
      db.e.drop()
      db.e.insert({"key1": "some-val-1", "key2": "some-val-2"})
      db.e.createIndex({'key1': 1})
      db.e.createIndex({'key2': 1})
      
      db.runCommand({"planCacheClearFilters": "e"})
      db.runCommand({"planCacheSetFilter": "e", 
          "query": {"key1": 1, "key2": 1},
          "indexes": [ {"key1": 1} ]})
      db.runCommand({"planCacheSetFilter": "e", 
          "query": {"key1": 1, "key2": 1},
          "projection": {"key1": 1},
          "indexes": [ {"key1": 1} ]})
      db.runCommand({"planCacheListFilters": "e"})
      __EOF
      
      mongo <<__EOF
      exp1 = db.e.find({"key1": "val1", "key2": "val2"}).explain()
      exp2 = db.e.find({"key1": "val1", "key2": "val2"}, {"key1": 1}).explain()
      print("MongoClient no projection: " + exp1.filterSet)
      print("MongoClient projection: " + exp2.filterSet)
      __EOF
      
      python <<__EOF
      from pymongo import MongoClient
      
      cl = MongoClient()
      db = cl["$DB"]
      e = db['e']
      
      curs = e.find({"key1": "val1", "key2": "val2"})
      print "Python no projection:", curs.explain()['filterSet']
      curs = e.find({"key1": "val1", "key2": "val2"}, projection=["key1"])
      print "Python projection:", curs.explain()['filterSet']
      __EOF
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            mba Marcin Barczy?ski
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: