Skip to content

Commit b03b239

Browse files
authored
Merge pull request #19 from BorntraegerMarc/update-many
feat(update): Adds possibility to call updateMany on MongoDB
2 parents 1388cbc + e5af362 commit b03b239

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ var MongodbDriver = Base.extend({
342342
case 'update':
343343
db.collection(collection)[command](options.query, options.update, options.options, callbackFunction);
344344
break;
345+
case 'updateMany':
346+
db.collection(collection)[command](options.query, options.update, options.options, callbackFunction);
347+
break;
345348
default:
346349
db[command](collection, callbackFunction);
347350
break;

test/mongodb_test.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,47 @@ vows.describe('mongodb').addBatch({
360360
}
361361
}
362362
}
363-
}).export(module);
363+
})
364+
.addBatch({
365+
'updateMany': {
366+
topic: function() {
367+
db.createCollection('event', function(err, collection) {
368+
if(err) {
369+
return this.callback(err);
370+
}
371+
db.insert('event', {id: 2, title: 'title'}, function(err) {
372+
if(err) {
373+
return this.callback(err);
374+
}
375+
376+
var command = 'updateMany';
377+
var renameFieldOptions = {
378+
query: {},
379+
update: {
380+
$rename: {
381+
title: 'titleUpdated'
382+
}
383+
},
384+
options: {}
385+
};
386+
387+
db._run(command, 'event', renameFieldOptions, function (err) {
388+
if(err) {
389+
return this.callback(err);
390+
}
391+
db._find('event', {titleUpdated: 'title'}, this.callback);
392+
}.bind(this));
393+
}.bind(this));
394+
}.bind(this));
395+
},
396+
397+
teardown: function() {
398+
db.dropCollection('event', this.callback);
399+
},
400+
401+
'with renamed row' : function(err, data) {
402+
assert.equal(data.length, 1);
403+
}
404+
}
405+
})
406+
.export(module);

0 commit comments

Comments
 (0)