Skip to content

Commit

Permalink
Merged fix/update-one-return-value into master
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Nov 7, 2016
2 parents 47f9831 + df39cea commit edb1428
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,21 +560,20 @@ export class Model<TDocument extends { _id?: any }, TInstance> {
conditions = this._helpers.convertToDB(conditions);

return new Bluebird<number>((resolve, reject) => {
if (opts.multi)
return this.collection.updateMany(conditions, changes, opts, (err, response) => {
if (err) return reject(err);
const callback = (err: Error, response: MongoDB.UpdateWriteOpResult) => {
if (err) return reject(err);

// New MongoDB 2.6+ response type
if (response.result && response.result.nModified !== undefined) return resolve(response.result.nModified);
// New MongoDB 2.6+ response type
if (response.result && response.result.nModified !== undefined) return resolve(response.result.nModified);

// Legacy response type
return resolve(response.result.n);
});
// Legacy response type
return resolve(response.result.n);
}

if (opts.multi)
return this.collection.updateMany(conditions, changes, opts, callback);

return this.collection.update(conditions, changes, opts, (err, response) => {
if (err) return reject(err);
return resolve(1);
})
return this.collection.updateOne(conditions, changes, opts, callback)
})
}).nodeify(callback);
}
Expand Down
1 change: 1 addition & 0 deletions test/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ describe("Model",() => {

it("should allow replacement updates to be conducted",() => {
return model.get().then(instance => {
instance.answer++;
return chai.expect(model.update(instance._id, instance.document, { multi: false })).to.eventually.equal(1);
});
});
Expand Down

0 comments on commit edb1428

Please sign in to comment.