Skip to content

Commit aabf3b2

Browse files
authored
Merge pull request #12167 from emiljanitzek/feature/bulk-write-types
fix(types): pass type to mongodb bulk write operation
2 parents 67c2e93 + 6b24fa0 commit aabf3b2

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

test/types/models.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,33 @@ function bulkWrite() {
282282
M.bulkWrite(ops);
283283
}
284284

285+
function bulkWriteAddToSet() {
286+
const schema = new Schema({
287+
arr: [String]
288+
});
289+
290+
const M = model('Test', schema);
291+
292+
const ops = [
293+
{
294+
updateOne: {
295+
filter: {
296+
arr: {
297+
$nin: ['abc']
298+
}
299+
},
300+
update: {
301+
$addToSet: {
302+
arr: 'abc'
303+
}
304+
}
305+
}
306+
}
307+
];
308+
309+
return M.bulkWrite(ops);
310+
}
311+
285312
export function autoTypedModel() {
286313
const AutoTypedSchema = autoTypedSchema();
287314
const AutoTypedModel = model('AutoTypeModel', AutoTypedSchema);

types/models.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ declare module 'mongoose' {
144144
* if you use `create()`) because with `bulkWrite()` there is only one network
145145
* round trip to the MongoDB server.
146146
*/
147-
bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation>, options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions, callback: Callback<mongodb.BulkWriteResult>): void;
148-
bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation>, callback: Callback<mongodb.BulkWriteResult>): void;
149-
bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation>, options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions): Promise<mongodb.BulkWriteResult>;
147+
bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T>>, options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions, callback: Callback<mongodb.BulkWriteResult>): void;
148+
bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T>>, callback: Callback<mongodb.BulkWriteResult>): void;
149+
bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation<T>>, options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions): Promise<mongodb.BulkWriteResult>;
150150

151151
/**
152152
* Sends multiple `save()` calls in a single `bulkWrite()`. This is faster than

0 commit comments

Comments
 (0)