From 6b36894dee7f7930bc457cb6e4d0402d2b5f178d Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 23 Oct 2018 18:07:17 -0600 Subject: [PATCH 1/2] feat: added arrayFilters to update operations, some cleanups --- types/mongodb/index.d.ts | 46 +++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 07b36603d4..be6a509a0f 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -707,8 +707,8 @@ export interface Collection { findOneAndReplace(filter: FilterQuery, replacement: Object, options: FindOneAndReplaceOption, callback: MongoCallback>): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndUpdate */ findOneAndUpdate(filter: FilterQuery, update: Object, callback: MongoCallback>): void; - findOneAndUpdate(filter: FilterQuery, update: Object, options?: FindOneAndReplaceOption): Promise>; - findOneAndUpdate(filter: FilterQuery, update: Object, options: FindOneAndReplaceOption, callback: MongoCallback>): void; + findOneAndUpdate(filter: FilterQuery, update: Object, options?: FindOneAndUpdateOption): Promise>; + findOneAndUpdate(filter: FilterQuery, update: Object, options: FindOneAndUpdateOption, callback: MongoCallback>): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#geoHaystackSearch */ geoHaystackSearch(x: number, y: number, callback: MongoCallback): void; geoHaystackSearch(x: number, y: number, options?: GeoHaystackSearchOptions): Promise; @@ -804,17 +804,17 @@ export interface Collection { /** @deprecated use updateOne, updateMany or bulkWrite */ update(filter: FilterQuery, update: UpdateQuery | TSchema, callback: MongoCallback): void; /** @deprecated use updateOne, updateMany or bulkWrite */ - update(filter: FilterQuery, update: UpdateQuery | TSchema, options?: ReplaceOneOptions & { multi?: boolean }): Promise; + update(filter: FilterQuery, update: UpdateQuery | TSchema, options?: UpdateOneOptions & { multi?: boolean }): Promise; /** @deprecated use updateOne, updateMany or bulkWrite */ - update(filter: FilterQuery, update: UpdateQuery | TSchema, options: ReplaceOneOptions & { multi?: boolean }, callback: MongoCallback): void; + update(filter: FilterQuery, update: UpdateQuery | TSchema, options: UpdateOneOptions & { multi?: boolean }, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#updateMany */ updateMany(filter: FilterQuery, update: UpdateQuery | TSchema, callback: MongoCallback): void; - updateMany(filter: FilterQuery, update: UpdateQuery | TSchema, options?: CommonOptions & { upsert?: boolean }): Promise; - updateMany(filter: FilterQuery, update: UpdateQuery | TSchema, options: CommonOptions & { upsert?: boolean }, callback: MongoCallback): void; + updateMany(filter: FilterQuery, update: UpdateQuery | TSchema, options?: UpdateManyOptions): Promise; + updateMany(filter: FilterQuery, update: UpdateQuery | TSchema, options: UpdateManyOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#updateOne */ updateOne(filter: FilterQuery, update: UpdateQuery | TSchema, callback: MongoCallback): void; - updateOne(filter: FilterQuery, update: UpdateQuery | TSchema, options?: ReplaceOneOptions): Promise; - updateOne(filter: FilterQuery, update: UpdateQuery | TSchema, options: ReplaceOneOptions, callback: MongoCallback): void; + updateOne(filter: FilterQuery, update: UpdateQuery | TSchema, options?: UpdateOneOptions): Promise; + updateOne(filter: FilterQuery, update: UpdateQuery | TSchema, options: UpdateOneOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#watch */ watch(pipeline?: Object[], options?: ChangeStreamOptions & { startAtClusterTime?: Timestamp, session?: ClientSession }): ChangeStream; } @@ -1167,6 +1167,17 @@ export interface FindOneAndReplaceOption { session?: ClientSession; } +/** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndUpdate */ +export interface FindOneAndUpdateOption { + projection?: Object; + sort?: Object; + maxTimeMS?: number; + upsert?: boolean; + returnOriginal?: boolean; + session?: ClientSession; + arrayFilters?: Object[]; +} + /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#geoHaystackSearch */ export interface GeoHaystackSearchOptions { readPreference?: ReadPreference | string; @@ -1356,6 +1367,25 @@ export interface ReplaceOneOptions extends CommonOptions { bypassDocumentValidation?: boolean; } +/** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#updateOne */ +export interface UpdateOneOptions extends CommonOptions { + upsert?: boolean; + w?: number | string; + wtimeout?: number; + j?: boolean; + bypassDocumentValidation?: boolean; + arrayFilters?: Object[]; +} + +/** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#updateMany */ +export interface UpdateManyOptions extends CommonOptions { + upsert?: boolean; + w?: number | string; + wtimeout?: number; + j?: boolean; + arrayFilters: Object[]; +} + /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#~updateWriteOpResult */ export interface UpdateWriteOpResult { result: { ok: number, n: number, nModified: number }; From f70415ab95ab5abef0692d17baf0c2b19a1e4772 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 25 Oct 2018 10:29:52 -0600 Subject: [PATCH 2/2] review: fixes based on review --- types/mongodb/index.d.ts | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index be6a509a0f..e7405ca7ef 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -1158,23 +1158,16 @@ export interface FindAndModifyWriteOpResultObject { } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndReplace */ -export interface FindOneAndReplaceOption { +export interface FindOneAndReplaceOption extends CommonOptions { projection?: Object; sort?: Object; maxTimeMS?: number; upsert?: boolean; returnOriginal?: boolean; - session?: ClientSession; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndUpdate */ -export interface FindOneAndUpdateOption { - projection?: Object; - sort?: Object; - maxTimeMS?: number; - upsert?: boolean; - returnOriginal?: boolean; - session?: ClientSession; +export interface FindOneAndUpdateOption extends FindOneAndReplaceOption { arrayFilters?: Object[]; } @@ -1368,21 +1361,13 @@ export interface ReplaceOneOptions extends CommonOptions { } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#updateOne */ -export interface UpdateOneOptions extends CommonOptions { - upsert?: boolean; - w?: number | string; - wtimeout?: number; - j?: boolean; - bypassDocumentValidation?: boolean; +export interface UpdateOneOptions extends ReplaceOneOptions { arrayFilters?: Object[]; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#updateMany */ export interface UpdateManyOptions extends CommonOptions { upsert?: boolean; - w?: number | string; - wtimeout?: number; - j?: boolean; arrayFilters: Object[]; }