Skip to content

Commit bc8d644

Browse files
committed
NODE-318 collection.update error while setting a function with serializeFunctions option
1 parent f681fa6 commit bc8d644

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

lib/collection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ Collection.prototype.update = function(selector, document, options, callback) {
636636
// Do we return the actual result document
637637
// Either use override on the function, or go back to default on either the collection
638638
// level or db
639-
options['serializeFunctions'] = options['serializeFunctions'] || this.s.serializeFunctions;
639+
finalOptions['serializeFunctions'] = options['serializeFunctions'] || this.s.serializeFunctions;
640640

641641
// Execute the operation
642642
var op = {q: selector, u: document};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
, "readable-stream": "1.0.31"
2121
},
2222
"devDependencies": {
23-
"integra": "0.1.7"
23+
"integra": "0.1.8"
2424
, "optimist": "0.6.1"
2525
, "bson": "~0.2"
2626
, "jsdoc": "3.3.0-alpha9"

test/functional/insert_tests.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,35 @@ exports.shouldCorrectlyApplyBitOperator = {
17811781
test.equal(1, doc.a);
17821782
test.equal(0, doc.b);
17831783

1784+
db.close();
1785+
test.done();
1786+
});
1787+
});
1788+
});
1789+
});
1790+
}
1791+
}
1792+
1793+
exports.shouldCorrectlyPerformInsertAndUpdateWithFunctionSerialization = {
1794+
// Add a tag that our runner can trigger on
1795+
// in this case we are setting that node needs to be higher than 0.10.X to run
1796+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
1797+
1798+
// The actual test we wish to run
1799+
test: function(configuration, test) {
1800+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {native_parser:false})
1801+
db.open(function(err, db) {
1802+
var col = db.collection('shouldCorrectlyPerformInsertAndUpdateWithFunctionSerialization', {serializeFunctions:true});
1803+
1804+
col.insert({a:1, f: function(x) {return x;}},function(err,doc){
1805+
test.equal(null,err);
1806+
1807+
col.update({a:1},{$set:{f: function(y){return y;}}},function(err,doc){
1808+
test.equal(null,err);
1809+
1810+
col.findOne({a:1}, function(err, doc) {
1811+
test.equal(null, err);
1812+
test.equal("function (y){return y;}", doc.f.code);
17841813
db.close();
17851814
test.done();
17861815
});

0 commit comments

Comments
 (0)