From 6b24fa02c0f1ecd528894ecf47c2207eb910c3a9 Mon Sep 17 00:00:00 2001 From: Emil Janitzek Date: Thu, 28 Jul 2022 19:29:21 +0200 Subject: [PATCH] fix(types): pass type to mongodb bulk write operation --- test/types/models.test.ts | 27 +++++++++++++++++++++++++++ types/models.d.ts | 6 +++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/test/types/models.test.ts b/test/types/models.test.ts index 62cf0e3d3bb..99cc52e1dad 100644 --- a/test/types/models.test.ts +++ b/test/types/models.test.ts @@ -282,6 +282,33 @@ function bulkWrite() { M.bulkWrite(ops); } +function bulkWriteAddToSet() { + const schema = new Schema({ + arr: [String] + }); + + const M = model('Test', schema); + + const ops = [ + { + updateOne: { + filter: { + arr: { + $nin: ['abc'] + } + }, + update: { + $addToSet: { + arr: 'abc' + } + } + } + } + ]; + + return M.bulkWrite(ops); +} + export function autoTypedModel() { const AutoTypedSchema = autoTypedSchema(); const AutoTypedModel = model('AutoTypeModel', AutoTypedSchema); diff --git a/types/models.d.ts b/types/models.d.ts index 490b6aa32c8..41020013228 100644 --- a/types/models.d.ts +++ b/types/models.d.ts @@ -144,9 +144,9 @@ declare module 'mongoose' { * if you use `create()`) because with `bulkWrite()` there is only one network * round trip to the MongoDB server. */ - bulkWrite(writes: Array, options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions, callback: Callback): void; - bulkWrite(writes: Array, callback: Callback): void; - bulkWrite(writes: Array, options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions): Promise; + bulkWrite(writes: Array>, options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions, callback: Callback): void; + bulkWrite(writes: Array>, callback: Callback): void; + bulkWrite(writes: Array>, options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions): Promise; /** * Sends multiple `save()` calls in a single `bulkWrite()`. This is faster than