Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-318

collection.update error while setting a function with "serializeFunctions" option

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.0.7
    • Affects Version/s: 2.0.5, 2.0.6
    • Component/s: None
    • Labels:
    • Environment:
      Node version: 0.10.33
      Mongodb version: 2.6.5
      OS: Mac OSX

      While trying to update a document on a collection that has the serializeFunctions option set, collection.update fails.
      Here is a simple code to illustrate the issue:

          var MongoClient = require('mongodb').MongoClient,
            test = require('assert');
          MongoClient.connect('mongodb://localhost:28888/test', function(err, db) {
            var collection = db.collection('usefunctions',{serializeFunctions:true});
            // Create an index on the a field
            collection.insert({a:1, f: function(x) {return x;}},function(err,doc){
              test.equal(null,err);
              collection.update({a:1},{$set:{f: function(x){return x;}}},function(err,doc){
                test.equal(null,err);
                db.close();
              });
            });
          });
      

      which raises the following error:
      AssertionError: null == {"name":"MongoError","index":0,"code":9,"errmsg":"'$set' is empty. You must specify a field like so: {$mod: {<field>: ..."}}}

      Looking into the code, it seems that the error is in the collection.js file, in the collection.prototype.update function definition. Replacing the line 639:

      options['serializeFunctions'] = options['serializeFunctions'] || this.s.serializeFunctions;
      

      with

      finalOptions['serializeFunctions'] = options['serializeFunctions'] || this.s.serializeFunctions;
      

      corrects the issue.

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            olivierchappe Olivier Chappe
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: