Skip to content

Commit 7d9edeb

Browse files
authored
update '_remove' method
#365 better support for shard cluster
1 parent 4f742e5 commit 7d9edeb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/service.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,17 @@ class Service extends AdapterService {
304304
if (id !== null) {
305305
query.$and = (query.$and || []).concat({ [this.id]: id });
306306

307-
return this.Model.findOneAndDelete(query, params.mongoose).lean(this.lean)
308-
.exec().then(result => {
307+
return this.Model.findById(id)
308+
.then((result) => {
309309
if (result === null) {
310310
throw new errors.NotFound(`No record found for id '${id}'`, query);
311311
}
312-
313-
return result;
314-
}).then(select(params, this.id)).catch(errorHandler);
312+
return this.Model.deleteOne(query, params.mongoose).lean(this.lean)
313+
.exec()
314+
.then(() => result)
315+
.then(select(params, this.id));
316+
})
317+
.catch(errorHandler);
315318
}
316319

317320
const findParams = Object.assign({}, params, {

0 commit comments

Comments
 (0)