|
|
@ -971,6 +971,8 @@ describe('Database', function () { |
|
|
|
], done); |
|
|
|
], done); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe.skip('Upserts', function () { |
|
|
|
|
|
|
|
|
|
|
|
it('Can perform upserts if needed', function (done) { |
|
|
|
it('Can perform upserts if needed', function (done) { |
|
|
|
d.update({ impossible: 'db is empty anyway' }, { newDoc: true }, {}, function (err, nr, upsert) { |
|
|
|
d.update({ impossible: 'db is empty anyway' }, { newDoc: true }, {}, function (err, nr, upsert) { |
|
|
|
assert.isNull(err); |
|
|
|
assert.isNull(err); |
|
|
@ -1004,6 +1006,32 @@ describe('Database', function () { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('If the update query is a normal object with no modifiers, it is the doc that will be upserted', function (done) { |
|
|
|
|
|
|
|
d.update({ $or: [{ a: 4 }, { a: 5 }] }, { hello: 'world', bloup: 'blap' }, { upsert: true }, function (err) { |
|
|
|
|
|
|
|
d.findOne({}, function (err, doc) { |
|
|
|
|
|
|
|
assert.isNull(err); |
|
|
|
|
|
|
|
Object.keys(doc).length.should.equal(3); |
|
|
|
|
|
|
|
doc.hello.should.equal('world'); |
|
|
|
|
|
|
|
doc.bloup.should.equal('blap'); |
|
|
|
|
|
|
|
done(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('If the update query contains modifiers, it is applied to the object resulting from removing all operator fro; the find query', function (done) { |
|
|
|
|
|
|
|
d.update({ $or: [{ a: 4 }, { a: 5 }] }, { hello: 'world', $inc: { bloup: 3 } }, { upsert: true }, function (err) { |
|
|
|
|
|
|
|
d.findOne({ hello: 'world' }, function (err, doc) { |
|
|
|
|
|
|
|
assert.isNull(err); |
|
|
|
|
|
|
|
Object.keys(doc).length.should.equal(3); |
|
|
|
|
|
|
|
doc.hello.should.equal('world'); |
|
|
|
|
|
|
|
doc.bloup.should.equal(3); |
|
|
|
|
|
|
|
done(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); // ==== End of 'Upserts' ==== //
|
|
|
|
|
|
|
|
|
|
|
|
it('Cannot perform update if the update query is not either registered-modifiers-only or copy-only, or contain badly formatted fields', function (done) { |
|
|
|
it('Cannot perform update if the update query is not either registered-modifiers-only or copy-only, or contain badly formatted fields', function (done) { |
|
|
|
d.insert({ something: 'yup' }, function () { |
|
|
|
d.insert({ something: 'yup' }, function () { |
|
|
|
d.update({}, { boom: { $badfield: 5 } }, { multi: false }, function (err) { |
|
|
|
d.update({}, { boom: { $badfield: 5 } }, { multi: false }, function (err) { |
|
|
|