Can upsert with modifiers

pull/2/head
Louis Chatriot 12 years ago
parent e423c169f3
commit e9baed16dc
  1. 2
      lib/datastore.js
  2. 2
      package.json
  3. 16
      test/db.test.js

@ -214,7 +214,7 @@ Datastore.prototype.update = function (query, newDoc, options, cb) {
if (doc) {
return cb();
} else {
return self.insert(newDoc, function (err) {
return self.insert(model.modify({}, newDoc), function (err) {
if (err) { return callback(err); }
return callback(null, 1, true);
});

@ -1,6 +1,6 @@
{
"name": "nedb",
"version": "0.3.1",
"version": "0.3.2",
"author": {
"name": "tldr.io",
"email": "hello@tldr.io"

@ -464,7 +464,23 @@ describe('Database', function () {
});
});
});
});
it('Can upsert a document even with modifiers', function (done) {
d.update({ bloup: 'blap' }, { $set: { hello: 'world' } }, { upsert: true }, function (err, nr, upsert) {
assert.isNull(err);
nr.should.equal(1);
upsert.should.equal(true);
d.find({}, function (err, docs) {
docs.length.should.equal(1);
Object.keys(docs[0]).length.should.equal(2);
docs[0].hello.should.equal('world');
assert.isDefined(docs[0]._id);
done();
});
});
});
}); // ==== End of 'Update' ==== //

Loading…
Cancel
Save