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

MongoDb $where clause returning incorrect results

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: 3.2.8
    • Fix Version/s: None
    • Component/s: Stability
    • Labels:
    • Environment:
    • Operating System:
      ALL
    • Steps To Reproduce:
      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}});`

      Description

      $where clause producing inconsistent results

      Please refer the steps to reproduce section for detailed description.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: