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

$where should return an informative error message when passed a CodeWithScope argument

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query
    • ALL
    • Query 2020-03-09

      Find command $where no longer respects the scope in CodeWithScope. For example, on 4.2:

      >>> db.test.insert_many([{"x": i} for i in range(10)])
      <pymongo.results.InsertManyResult object at 0x109151e80>
      >>> len(list(db.test.find().where('this.x < 3')))
      3
      >>> len(list(db.test.find().where(Code('this.x < i', {'i':3}))))
      3
      

      On v4.3.3-387-g46ee960:

      >>> db.test.insert_many([{"x": i} for i in range(10)])
      <pymongo.results.InsertManyResult object at 0x109151e80>
      >>> len(list(db.test.find().where('this.x < 3')))
      3
      >>> len(list(db.test.find().where(Code('this.x < i', {'i':3}))))
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/shane/git/mongo-python-driver/pymongo/cursor.py", line 1156, in next
          if len(self.__data) or self._refresh():
        File "/Users/shane/git/mongo-python-driver/pymongo/cursor.py", line 1073, in _refresh
          self.__send_message(q)
        File "/Users/shane/git/mongo-python-driver/pymongo/cursor.py", line 953, in __send_message
          response = client._run_operation_with_response(
        File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1342, in _run_operation_with_response
          return self._retryable_read(
        File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1464, in _retryable_read
          return func(session, server, sock_info, slave_ok)
        File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1334, in _cmd
          return server.run_operation_with_response(
        File "/Users/shane/git/mongo-python-driver/pymongo/server.py", line 136, in run_operation_with_response
          _check_command_response(first)
        File "/Users/shane/git/mongo-python-driver/pymongo/helpers.py", line 161, in _check_command_response
          raise OperationFailure(msg % errmsg, code, response)
      pymongo.errors.OperationFailure: ReferenceError: i is not defined :
      @:1:15
      

      Could this be caused by SERVER-45454 or SERVER-46098?

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: