Comparing version 0.1.15 to 0.2.0
0.2.0 / 2012-07-14 | ||
================== | ||
* collection: added `count` | ||
0.1.15 / 2012-07-14 | ||
@@ -3,0 +8,0 @@ =================== |
@@ -391,2 +391,28 @@ | ||
/** | ||
* count | ||
* | ||
* @param {Object} query | ||
* @param {Function} completion callback | ||
* @return {Promise} | ||
* @api public | ||
*/ | ||
Collection.prototype.count = function (query, fn) { | ||
var promise = new Promise(this, 'find') | ||
if (fn) { | ||
promise.complete(fn); | ||
} | ||
// cast | ||
query = this.cast(query); | ||
// query | ||
debug('%s count "%j"', this.name, query); | ||
this.col.count(query, promise.fulfill); | ||
return promise; | ||
}; | ||
/** | ||
* findOne | ||
@@ -393,0 +419,0 @@ * |
{ | ||
"name": "monk" | ||
, "version": "0.1.15" | ||
, "version": "0.2.0" | ||
, "main": "lib/monk.js" | ||
@@ -5,0 +5,0 @@ , "tags": ["mongodb", "mongo", "driver"] |
@@ -128,2 +128,21 @@ | ||
describe('counting', function () { | ||
it('should work', function (done) { | ||
users.count({ a: 'counting' }, function (err, count) { | ||
expect(err).to.be(null); | ||
expect(count).to.be(0); | ||
users.insert({ a: 'counting' }, function (err) { | ||
expect(err).to.be(null); | ||
users.count({ a: 'counting' }, function (err, count) { | ||
expect(err).to.be(null); | ||
expect(count).to.be(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('updating', function () { | ||
@@ -130,0 +149,0 @@ it('should update', function (done) { |
33806
982