From 29b43a06a20374378ecbb6c0bcd2a32b32490f4c Mon Sep 17 00:00:00 2001 From: Jordan Stout Date: Fri, 8 Nov 2019 14:49:20 -0800 Subject: [PATCH] [mongodb] nested array/object support for PullOperator (#40056) --- types/mongodb/index.d.ts | 4 +++- types/mongodb/test/collection/updateX.ts | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 77e3dd3cac..e5a0879ce0 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -1208,7 +1208,7 @@ export type PushOperator = ({ }; export type PullOperator = ({ - readonly [key in KeysOfAType]?: Unpacked | QuerySelector>; + readonly [key in KeysOfAType]?: Partial> | ObjectQuerySelector>; } & NotAcceptedFields) & { readonly [key: string]: QuerySelector | any; @@ -1365,6 +1365,8 @@ export type RootQuerySelector = { [key: string]: any; }; +export type ObjectQuerySelector = T extends object ? {[key in keyof T]?: QuerySelector } : QuerySelector; + export type Condition = MongoAltQuery | QuerySelector>; export type FilterQuery = { diff --git a/types/mongodb/test/collection/updateX.ts b/types/mongodb/test/collection/updateX.ts index 29404c8e06..bc5396858a 100644 --- a/types/mongodb/test/collection/updateX.ts +++ b/types/mongodb/test/collection/updateX.ts @@ -7,7 +7,8 @@ async function run() { const db = client.db('test'); interface SubTestModel { - field: string; + field1: string; + field2: string; } // test with collection type @@ -106,6 +107,8 @@ async function run() { buildUpdateQuery({ $pull: { fruitTags: { $in: ['a'] } } }); buildUpdateQuery({ $pull: { 'dot.notation': 1 } }); buildUpdateQuery({ $pull: { 'subInterfaceArray.$[]': { $in: ['a'] } } }); + buildUpdateQuery({ $pull: { subInterfaceArray: { field1: 'a' } }}); + buildUpdateQuery({ $pull: { subInterfaceArray: { field1: { $in: ['a'] } } }}); buildUpdateQuery({ $push: { fruitTags: 'a' } }); buildUpdateQuery({ $push: { fruitTags: { $each: ['a'] } } });