diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index a6d8a7b822..d4f80af795 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -1545,6 +1545,9 @@ declare module "mongoose" { callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery; findOneAndUpdate(query: any | Query, update: any, callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery; + findOneAndUpdate(query: any | Query, update: any, + options: { upsert: true, new: true } & QueryFindOneAndUpdateOptions, + callback?: (err: any, doc: DocType, res: any) => void): DocumentQuery; findOneAndUpdate(query: any | Query, update: any, options: QueryFindOneAndUpdateOptions, callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery; @@ -2520,6 +2523,9 @@ declare module "mongoose" { findByIdAndUpdate(): DocumentQuery; findByIdAndUpdate(id: any | number | string, update: any, callback?: (err: any, res: T | null) => void): DocumentQuery; + findByIdAndUpdate(id: any | number | string, update: any, + options: { upsert: true, new: true } & ModelFindByIdAndUpdateOptions, + callback?: (err: any, res: T) => void): DocumentQuery; findByIdAndUpdate(id: any | number | string, update: any, options: ModelFindByIdAndUpdateOptions, callback?: (err: any, res: T | null) => void): DocumentQuery; @@ -2565,6 +2571,9 @@ declare module "mongoose" { findOneAndUpdate(): DocumentQuery; findOneAndUpdate(conditions: any, update: any, callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery; + findOneAndUpdate(conditions: any, update: any, + options: { upsert: true, new: true } & ModelFindOneAndUpdateOptions, + callback?: (err: any, doc: T, res: any) => void): DocumentQuery; findOneAndUpdate(conditions: any, update: any, options: ModelFindOneAndUpdateOptions, callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery; diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index bf2f61f4a3..fc43549f8e 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -758,6 +758,7 @@ query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, { }, cb); query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, cb); query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}); +query.findOneAndUpdate({}, {}, { upsert: true, new: true }); query.findOneAndUpdate({name: 'bb'}, cb); query.findOneAndUpdate({name: 'bb'}); query.findOneAndUpdate(cb); @@ -1387,6 +1388,7 @@ MongoModel.findByIdAndRemove(999); MongoModel.findByIdAndRemove(); MongoModel.findByIdAndUpdate(999, {}, {}, cb); MongoModel.findByIdAndUpdate(999, {}, {}); +MongoModel.findByIdAndUpdate(999, {}, { upsert: true, new: true }); MongoModel.findByIdAndUpdate(999, {}, cb); MongoModel.findByIdAndUpdate(999, {}); MongoModel.findByIdAndUpdate(); @@ -1415,6 +1417,7 @@ MongoModel.findOneAndRemove({}); MongoModel.findOneAndRemove(); MongoModel.findOneAndUpdate({}, {}, {}, cb); MongoModel.findOneAndUpdate({}, {}, {}); +MongoModel.findOneAndUpdate({}, {}, { upsert: true, new: true }); MongoModel.findOneAndUpdate({}, {}, cb); MongoModel.findOneAndUpdate({}, {}); MongoModel.findOneAndUpdate(); diff --git a/types/mongoose/v4/index.d.ts b/types/mongoose/v4/index.d.ts index 4a4b7d224e..6cd9c5e152 100644 --- a/types/mongoose/v4/index.d.ts +++ b/types/mongoose/v4/index.d.ts @@ -1602,6 +1602,9 @@ declare module "mongoose" { callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery; findOneAndUpdate(query: any | Query, update: any, callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery; + findOneAndUpdate(query: any | Query, update: any, + options: { upsert: true, new: true } & QueryFindOneAndUpdateOptions, + callback?: (err: any, doc: DocType, res: any) => void): DocumentQuery; findOneAndUpdate(query: any | Query, update: any, options: QueryFindOneAndUpdateOptions, callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery; @@ -2528,6 +2531,9 @@ declare module "mongoose" { findByIdAndUpdate(): DocumentQuery; findByIdAndUpdate(id: any | number | string, update: any, callback?: (err: any, res: T | null) => void): DocumentQuery; + findByIdAndUpdate(id: any | number | string, update: any, + options: { upsert: true, new: true } & ModelFindByIdAndUpdateOptions, + callback?: (err: any, res: T) => void): DocumentQuery; findByIdAndUpdate(id: any | number | string, update: any, options: ModelFindByIdAndUpdateOptions, callback?: (err: any, res: T | null) => void): DocumentQuery; @@ -2573,6 +2579,9 @@ declare module "mongoose" { findOneAndUpdate(): DocumentQuery; findOneAndUpdate(conditions: any, update: any, callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery; + findOneAndUpdate(conditions: any, update: any, + options: { upsert: true, new: true } & ModelFindOneAndUpdateOptions, + callback?: (err: any, doc: T, res: any) => void): DocumentQuery; findOneAndUpdate(conditions: any, update: any, options: ModelFindOneAndUpdateOptions, callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery; diff --git a/types/mongoose/v4/mongoose-tests.ts b/types/mongoose/v4/mongoose-tests.ts index 64214fe983..170a005b49 100644 --- a/types/mongoose/v4/mongoose-tests.ts +++ b/types/mongoose/v4/mongoose-tests.ts @@ -743,6 +743,8 @@ query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, { }, cb); query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, cb); query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}); +query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, { }); +query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, { upsert: true, new: true }); query.findOneAndUpdate({name: 'bb'}, cb); query.findOneAndUpdate({name: 'bb'}); query.findOneAndUpdate(cb); @@ -1371,6 +1373,7 @@ MongoModel.findByIdAndRemove(999); MongoModel.findByIdAndRemove(); MongoModel.findByIdAndUpdate(999, {}, {}, cb); MongoModel.findByIdAndUpdate(999, {}, {}); +MongoModel.findByIdAndUpdate(999, {}, { new: true, upsert: true }, cb); MongoModel.findByIdAndUpdate(999, {}, cb); MongoModel.findByIdAndUpdate(999, {}); MongoModel.findByIdAndUpdate(); @@ -1399,6 +1402,7 @@ MongoModel.findOneAndRemove({}); MongoModel.findOneAndRemove(); MongoModel.findOneAndUpdate({}, {}, {}, cb); MongoModel.findOneAndUpdate({}, {}, {}); +MongoModel.findOneAndUpdate({}, {}, { upsert: true, new: true }); MongoModel.findOneAndUpdate({}, {}, cb); MongoModel.findOneAndUpdate({}, {}); MongoModel.findOneAndUpdate();