Skip to content

Commit

Permalink
add .command()
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxin committed May 11, 2015
1 parent fabbb94 commit 447084b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ DB.prototype.catch = function (reject) {
return this.connect.catch(reject)
}

DB.prototype.command = function (command, options) {
assert(this.raw, 'Wait to connect first!')
options = options || {}
var self = this
return new Promise(function (resolve, reject) {
self.raw.command(command, options, function (err, result) {
if (err) return reject(err)
resolve(result)
})
})
}

DB.prototype.collection = function (name) {
if (this[name]) return this[name]
assert(this.raw, 'Wait to connect first!')
Expand Down
10 changes: 10 additions & 0 deletions test/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

describe('.command()', function () {
it('(options)', function () {
return db.command({
count: 'mongodbtest'
}).then(function (result) {
assert(result.n)
})
})
})
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ require('./aggregate')
require('./mapreduce')
require('./batch')
require('./indexes')
require('./command')

0 comments on commit 447084b

Please sign in to comment.