-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
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
-
Empty show more show less
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.