Comparing version 0.1.9 to 0.1.10
0.1.10 / 2012-05-21 | ||
=================== | ||
* Enhanced findAndModify default behavior for upserts. | ||
* Fixed findAndModify. | ||
0.1.9 / 2012-05-16 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -247,2 +247,7 @@ | ||
// `new` defaults to `true` for upserts | ||
if (null == opts.new && opts.upsert) { | ||
opts.new = true; | ||
} | ||
if (fn) { | ||
@@ -258,3 +263,9 @@ promise.on('complete', fn); | ||
debug('%s findAndModify "%j" with "%j"', this.name, query.query, query.update); | ||
this.col.findAndModify(query, this.opts(opts), promise.fulfill); | ||
this.col.findAndModify( | ||
query.query | ||
, [] | ||
, query.update | ||
, this.opts(opts) | ||
, promise.fulfill | ||
); | ||
@@ -261,0 +272,0 @@ return promise; |
{ | ||
"name": "monk" | ||
, "version": "0.1.9" | ||
, "version": "0.1.10" | ||
, "main": "lib/monk.js" | ||
@@ -5,0 +5,0 @@ , "dependencies": { |
@@ -127,2 +127,43 @@ | ||
describe('findAndModifying', function () { | ||
it('should alter an existing document', function (done) { | ||
var rand = 'now-' + Date.now(); | ||
users.insert({ find: rand }, function (err, doc) { | ||
expect(err).to.be(null); | ||
users.findAndModify({ find: rand }, { find: 'woot' }, { new: true }, function (err, doc) { | ||
expect(err).to.be(null); | ||
expect(doc.find).to.be('woot'); | ||
users.findById(doc._id, function (err, found) { | ||
expect(err).to.be(null); | ||
expect(found._id.toString()).to.equal(doc._id.toString()); | ||
expect(found.find).to.be('woot'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('should upsert', function (done) { | ||
function callback (err, doc) { | ||
if (err) return done(err); | ||
expect(doc.find).to.be(rand); | ||
users.findOne({ find: rand }, function (err, found) { | ||
expect(err).to.be(null); | ||
expect(found._id.toString()).to.be(doc._id.toString()); | ||
expect(found.find).to.be(rand); | ||
done(); | ||
}); | ||
}; | ||
var rand = 'now-' + Date.now(); | ||
users.findAndModify( | ||
{ find: rand } | ||
, { find: rand } | ||
, { upsert: true } | ||
, callback | ||
); | ||
}); | ||
}); | ||
describe('options', function () { | ||
@@ -129,0 +170,0 @@ it('should allow defaults', function (done) { |
30019
884