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

MongoDb $where clause returning incorrect results

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Cannot Reproduce
    • 3.2.8
    • None
    • Stability
    • 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}});`

    Description

      $where clause producing inconsistent results

      Please refer the steps to reproduce section for detailed description.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: