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

MongoDb $where clause returning incorrect results

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.8
    • Component/s: Stability
    • Environment:
    • ALL
    • Hide

      Create collection (EMPLOYEES) and insert the below doc.

      {"_id" : ObjectId("57d1a113666f6fc012f2708f"), "employee_id" : 107, "first_name" : "Diana", "last_name" : "Lorentz", "email" : "DLORENTZ", "phone_number" : "590.423.5567", "hire_date" : "07-FEB-99", "job_id" : "IT_PROG", "salary" : 4200, "manager_id" : 103, "department_id" : 60}

      Now execute the below 2 query and compare the results

      db.EMPLOYEES.find({$where: " return false "});`

      if i execute the the same logic in other way using the below query, its returning records from EMPLOYEES collection which is incorrect.

      `db.EMPLOYEES.find({$where: function(){return false}});`

      Show
      Create collection (EMPLOYEES) and insert the below doc. {"_id" : ObjectId("57d1a113666f6fc012f2708f"), "employee_id" : 107, "first_name" : "Diana", "last_name" : "Lorentz", "email" : "DLORENTZ", "phone_number" : "590.423.5567", "hire_date" : "07-FEB-99", "job_id" : "IT_PROG", "salary" : 4200, "manager_id" : 103, "department_id" : 60} Now execute the below 2 query and compare the results db.EMPLOYEES.find({$where: " return false "});` if i execute the the same logic in other way using the below query, its returning records from EMPLOYEES collection which is incorrect. `db.EMPLOYEES.find({$where: function(){return false}});`

      $where clause producing inconsistent results

      Please refer the steps to reproduce section for detailed description.

            Assignee:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Reporter:
            ArockiAnto Arockia Anto [X]
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: