Skip to content

Commit 7aa7160

Browse files
committed
NODE-843 Executing bulk operations overwrites write concern parameter
1 parent 9bb3ddc commit 7aa7160

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

lib/bulk/ordered.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ OrderedBulkOperation.prototype.execute = function(_writeConcern, callback) {
487487
if(this.s.executed) throw new toError("batch cannot be re-executed");
488488
if(typeof _writeConcern == 'function') {
489489
callback = _writeConcern;
490-
} else {
490+
} else if(_writeConcern && typeof _writeConcern == 'object') {
491491
this.s.writeConcern = _writeConcern;
492492
}
493493

lib/bulk/unordered.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ UnorderedBulkOperation.prototype.execute = function(_writeConcern, callback) {
488488
if(this.s.executed) throw toError("batch cannot be re-executed");
489489
if(typeof _writeConcern == 'function') {
490490
callback = _writeConcern;
491-
} else {
491+
} else if(_writeConcern && typeof _writeConcern == 'object') {
492492
this.s.writeConcern = _writeConcern;
493493
}
494494

test/functional/promises_collection_tests.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,53 @@ exports['Should correctly return failing Promise when array passed into insertOn
205205
});
206206
}
207207
}
208+
209+
exports['Should correctly execute unordered bulk operation in promise form'] = {
210+
metadata: { requires: { promises:true, topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
211+
212+
// The actual test we wish to run
213+
test: function(configuration, test) {
214+
var MongoClient = configuration.require.MongoClient;
215+
var url = configuration.url();
216+
url = url.indexOf('?') != -1
217+
? f('%s&%s', url, 'maxPoolSize=100')
218+
: f('%s?%s', url, 'maxPoolSize=100');
219+
220+
MongoClient.connect(url).then(function(db) {
221+
var bulk = db.collection('unordered_bulk_promise_form').initializeUnorderedBulkOp({ w:1 });
222+
bulk.insert({a:1});
223+
bulk.execute().then(function(r) {
224+
test.ok(r);
225+
test.deepEqual({w:1}, bulk.s.writeConcern);
226+
227+
db.close();
228+
test.done();
229+
});
230+
});
231+
}
232+
}
233+
234+
exports['Should correctly execute ordered bulk operation in promise form'] = {
235+
metadata: { requires: { promises:true, topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
236+
237+
// The actual test we wish to run
238+
test: function(configuration, test) {
239+
var MongoClient = configuration.require.MongoClient;
240+
var url = configuration.url();
241+
url = url.indexOf('?') != -1
242+
? f('%s&%s', url, 'maxPoolSize=100')
243+
: f('%s?%s', url, 'maxPoolSize=100');
244+
245+
MongoClient.connect(url).then(function(db) {
246+
var bulk = db.collection('unordered_bulk_promise_form').initializeOrderedBulkOp({ w:1 });
247+
bulk.insert({a:1});
248+
bulk.execute().then(function(r) {
249+
test.ok(r);
250+
test.deepEqual({w:1}, bulk.s.writeConcern);
251+
252+
db.close();
253+
test.done();
254+
});
255+
});
256+
}
257+
}

0 commit comments

Comments
 (0)