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

$where clause invoked twice

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.5.4
    • Component/s: Querying
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Hide
      db.collection.drop();
      db.collection.insert({_id: 1, foo: 'bar'});
      db.collection.find({
        _id: 1,
        foo: 'bar',
        $where: function() {
            print('$where run with: ' + tojson(obj));
            return true;
        }
      });
      

      This logs:

      2013-11-20T18:02:41.551-0500 [conn9] $where run with: { "_id" : 1, "foo" : "bar" }
      2013-11-20T18:02:41.553-0500 [conn9] $where run with: { "_id" : 1, "foo" : "bar" }
      

      If you remove the _id and foo filters from the query, then the JS function only runs once.

      Show
      db.collection.drop(); db.collection.insert({_id: 1, foo: 'bar' }); db.collection.find({ _id: 1, foo: 'bar' , $where: function() { print( '$where run with: ' + tojson(obj)); return true ; } }); This logs: 2013-11-20T18:02:41.551-0500 [conn9] $where run with: { "_id" : 1, "foo" : "bar" } 2013-11-20T18:02:41.553-0500 [conn9] $where run with: { "_id" : 1, "foo" : "bar" } If you remove the _id and foo filters from the query, then the JS function only runs once.

      If a $where clause is combined with other filters in a query, the Javascript function in the $where clause is invoked twice.

            Assignee:
            hari.khalsa@10gen.com hari.khalsa@10gen.com
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: