Skip to content

Commit

Permalink
update '_remove' method
Browse files Browse the repository at this point in the history
#365 better support for shard cluster
  • Loading branch information
sarkistlt authored Dec 24, 2019
1 parent 4f742e5 commit 7d9edeb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,17 @@ class Service extends AdapterService {
if (id !== null) {
query.$and = (query.$and || []).concat({ [this.id]: id });

return this.Model.findOneAndDelete(query, params.mongoose).lean(this.lean)
.exec().then(result => {
return this.Model.findById(id)
.then((result) => {
if (result === null) {
throw new errors.NotFound(`No record found for id '${id}'`, query);
}

return result;
}).then(select(params, this.id)).catch(errorHandler);
return this.Model.deleteOne(query, params.mongoose).lean(this.lean)
.exec()
.then(() => result)
.then(select(params, this.id));
})
.catch(errorHandler);
}

const findParams = Object.assign({}, params, {
Expand Down

0 comments on commit 7d9edeb

Please sign in to comment.