From c43bcd9fd79979424220c530ef43f429b094c2ef Mon Sep 17 00:00:00 2001 From: Dyma <32801166+dymafr@users.noreply.github.com> Date: Fri, 14 Sep 2018 19:22:28 +0200 Subject: [PATCH] Add findByIdAndDelete() method (#28893) findByIdAndDelete() recommended method is missing. Mongoose docs: https://mongoosejs.com/docs/api.html#model_Model.findByIdAndDelete MongoDb docs: https://docs.mongodb.com/manual/reference/method/db.collection.findOneAndDelete/ --- types/mongoose/index.d.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 3534f82f49..70a4247d07 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -2759,6 +2759,24 @@ declare module "mongoose" { /** sets the document fields to return */ select?: any; }, callback?: (err: any, res: T | null) => void): DocumentQuery; + + + /** + * Issue a mongodb findOneAndDelete command by a document's _id field. + * findByIdAndDelete(id, ...) is equivalent to findByIdAndDelete({ _id: id }, ...). + * Finds a matching document, removes it, passing the found document (if any) to the callback. + * Executes immediately if callback is passed, else a Query object is returned. + * @param id value of _id to query by + */ + findByIdAndDelete(): DocumentQuery; + findByIdAndDelete(id: any | number | string, + callback?: (err: any, res: T | null) => void): DocumentQuery; + findByIdAndDelete(id: any | number | string, options: { + /** if multiple docs are found by the conditions, sets the sort order to choose which doc to update */ + sort?: any; + /** sets the document fields to return */ + select?: any; + }, callback?: (err: any, res: T | null) => void): DocumentQuery; /** * Issues a mongodb findAndModify update command by a document's _id field. findByIdAndUpdate(id, ...)