|
|
|
@ -1647,6 +1647,86 @@ describe('Database', function () { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe("Callback signature", function () { |
|
|
|
|
|
|
|
|
|
it("Regular update, multi false", function (done) { |
|
|
|
|
d.insert({ a: 1 }); |
|
|
|
|
d.insert({ a: 2 }); |
|
|
|
|
|
|
|
|
|
// returnUpdatedDocs set to false
|
|
|
|
|
d.update({ a: 1 }, { $set: { b: 20 } }, {}, function (err, numAffected, affectedDocuments, upsert) { |
|
|
|
|
assert.isNull(err); |
|
|
|
|
numAffected.should.equal(1); |
|
|
|
|
assert.isUndefined(affectedDocuments); |
|
|
|
|
assert.isUndefined(upsert); |
|
|
|
|
|
|
|
|
|
// returnUpdatedDocs set to true
|
|
|
|
|
d.update({ a: 1 }, { $set: { b: 21 } }, { returnUpdatedDocs: true }, function (err, numAffected, affectedDocuments, upsert) { |
|
|
|
|
assert.isNull(err); |
|
|
|
|
numAffected.should.equal(1); |
|
|
|
|
affectedDocuments.a.should.equal(1); |
|
|
|
|
affectedDocuments.b.should.equal(21); |
|
|
|
|
assert.isUndefined(upsert); |
|
|
|
|
|
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("Regular update, multi true", function (done) { |
|
|
|
|
d.insert({ a: 1 }); |
|
|
|
|
d.insert({ a: 2 }); |
|
|
|
|
|
|
|
|
|
// returnUpdatedDocs set to false
|
|
|
|
|
d.update({}, { $set: { b: 20 } }, { multi: true }, function (err, numAffected, affectedDocuments, upsert) { |
|
|
|
|
assert.isNull(err); |
|
|
|
|
numAffected.should.equal(2); |
|
|
|
|
assert.isUndefined(affectedDocuments); |
|
|
|
|
assert.isUndefined(upsert); |
|
|
|
|
|
|
|
|
|
// returnUpdatedDocs set to true
|
|
|
|
|
d.update({}, { $set: { b: 21 } }, { multi: true, returnUpdatedDocs: true }, function (err, numAffected, affectedDocuments, upsert) { |
|
|
|
|
assert.isNull(err); |
|
|
|
|
numAffected.should.equal(2); |
|
|
|
|
affectedDocuments.length.should.equal(2); |
|
|
|
|
assert.isUndefined(upsert); |
|
|
|
|
|
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("Upsert", function (done) { |
|
|
|
|
d.insert({ a: 1 }); |
|
|
|
|
d.insert({ a: 2 }); |
|
|
|
|
|
|
|
|
|
// Upsert flag not set
|
|
|
|
|
d.update({ a: 3 }, { $set: { b: 20 } }, {}, function (err, numAffected, affectedDocuments, upsert) { |
|
|
|
|
assert.isNull(err); |
|
|
|
|
numAffected.should.equal(0); |
|
|
|
|
assert.isUndefined(affectedDocuments); |
|
|
|
|
assert.isUndefined(upsert); |
|
|
|
|
|
|
|
|
|
// Upsert flag set
|
|
|
|
|
d.update({ a: 3 }, { $set: { b: 21 } }, { upsert: true }, function (err, numAffected, affectedDocuments, upsert) { |
|
|
|
|
assert.isNull(err); |
|
|
|
|
numAffected.should.equal(1); |
|
|
|
|
affectedDocuments.a.should.equal(3); |
|
|
|
|
affectedDocuments.b.should.equal(21); |
|
|
|
|
upsert.should.equal(true); |
|
|
|
|
|
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
|
docs.length.should.equal(3); |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); // ==== End of 'Update - Callback signature' ==== //
|
|
|
|
|
|
|
|
|
|
}); // ==== End of 'Update' ==== //
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|