Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ var MongodbDriver = Base.extend({
return this._run('insert', this.internals.seedTable, {name: name, run_on: new Date()})
.nodeify(callback);
},

/**
* Returns the DB instance so custom updates can be made.
* NOTE: This method exceptionally does not call close() on the database driver when the promise resolves. So the getDbInstance method caller
* needs to call .close() on it's own after finish working with the database driver.
*
* @param callback with the database driver as 2nd callback argument
*/
getDbInstance: function (callback) {
return this._run('getDbInstance', null, {run_on: new Date()})
.nodeify(callback);
},

/**
* Runs a query
Expand Down Expand Up @@ -345,6 +357,9 @@ var MongodbDriver = Base.extend({
case 'updateMany':
db.collection(collection)[command](options.query, options.update, options.options, callbackFunction);
break;
case 'getDbInstance':
prCB(null, db); // When the user wants to get the DB instance we need to return the promise callback, so the DB connection is not automatically closed
break;
default:
db[command](collection, callbackFunction);
break;
Expand Down
14 changes: 14 additions & 0 deletions test/mongodb_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,18 @@ vows
}
}
})
.addBatch({
getDbInstance: {
topic: function() {
db.getDbInstance(this.callback);
},

teardown: function() {
},

"has database reference": function(err, db) {
assert.isNotNull(db);
}
}
})
.export(module);