From 4eeba5a9a77e757b40722e11407d4f35d0ebdffa Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 11 Jan 2023 16:43:01 -0500 Subject: [PATCH 01/10] feat!: remove dot notation support by default --- src/index.ts | 3 + src/mongo_types.ts | 81 ++++++++++++++----- .../collection/recursive-types.test-d.ts | 59 ++++++-------- .../community/collection/updateX.test-d.ts | 12 +-- 4 files changed, 94 insertions(+), 61 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0d0718b43b6..b52316dff9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -309,6 +309,9 @@ export type { BitwiseFilter, BSONTypeAlias, Condition, + DotNotationFilter, + DotNotationMatchKeysAndValues, + DotNotationUpdateFilter, EnhancedOmit, Filter, FilterOperations, diff --git a/src/mongo_types.ts b/src/mongo_types.ts index 2408d7a88f4..c611889f5f4 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -65,13 +65,9 @@ export type EnhancedOmit = string extends keyof TRecor export type WithoutId = Omit; /** A MongoDB filter can be some portion of the schema or a set of operators @public */ -export type Filter = - | Partial - | ({ - [Property in Join, []>, '.'>]?: Condition< - PropertyType, Property> - >; - } & RootFilterOperators>); +export type Filter = { + [P in keyof WithId]?: Condition[P]>; +} & RootFilterOperators>; /** @public */ export type Condition = AlternativeType | FilterOperators>; @@ -247,19 +243,7 @@ export type OnlyFieldsOfType; /** @public */ -export type MatchKeysAndValues = Readonly< - { - [Property in Join, '.'>]?: PropertyType; - } & { - [Property in `${NestedPathsOfType}.$${`[${string}]` | ''}`]?: ArrayElement< - PropertyType - >; - } & { - [Property in `${NestedPathsOfType[]>}.$${ - | `[${string}]` - | ''}.${string}`]?: any; // Could be further narrowed - } & Document ->; +export type MatchKeysAndValues = Readonly> & Record; /** @public */ export type AddToSetOperators = { @@ -541,3 +525,60 @@ export type NestedPathsOfType = KeysOfAType< }, Type >; + +/** + * @public + * @experimental + */ +export type DotNotationFilter = + | Partial + | ({ + [Property in Join, []>, '.'>]?: Condition< + PropertyType, Property> + >; + } & RootFilterOperators>); + +/** + * @public + * @experimental + */ +export type DotNotationUpdateFilter = { + $currentDate?: OnlyFieldsOfType< + TSchema, + Date | Timestamp, + true | { $type: 'date' | 'timestamp' } + >; + $inc?: OnlyFieldsOfType; + $min?: DotNotationMatchKeysAndValues; + $max?: DotNotationMatchKeysAndValues; + $mul?: OnlyFieldsOfType; + $rename?: Record; + $set?: DotNotationMatchKeysAndValues; + $setOnInsert?: DotNotationMatchKeysAndValues; + $unset?: OnlyFieldsOfType; + $addToSet?: SetFields; + $pop?: OnlyFieldsOfType, 1 | -1>; + $pull?: PullOperator; + $push?: PushOperator; + $pullAll?: PullAllOperator; + $bit?: OnlyFieldsOfType< + TSchema, + NumericType | undefined, + { and: IntegerType } | { or: IntegerType } | { xor: IntegerType } + >; +} & Document; + +/** @public */ +export type DotNotationMatchKeysAndValues = Readonly< + { + [Property in Join, '.'>]?: PropertyType; + } & { + [Property in `${NestedPathsOfType}.$${`[${string}]` | ''}`]?: ArrayElement< + PropertyType + >; + } & { + [Property in `${NestedPathsOfType[]>}.$${ + | `[${string}]` + | ''}.${string}`]?: any; // Could be further narrowed + } & Document +>; diff --git a/test/types/community/collection/recursive-types.test-d.ts b/test/types/community/collection/recursive-types.test-d.ts index cd1927e0cf4..e90528d9799 100644 --- a/test/types/community/collection/recursive-types.test-d.ts +++ b/test/types/community/collection/recursive-types.test-d.ts @@ -1,6 +1,11 @@ import { expectAssignable, expectError, expectNotAssignable, expectNotType } from 'tsd'; -import type { Collection, Filter, UpdateFilter } from '../../../../src'; +import type { + Collection, + DotNotationFilter, + DotNotationUpdateFilter, + UpdateFilter +} from '../../../../src'; /** * mutually recursive types are not supported and will not get type safety @@ -15,7 +20,7 @@ interface Book { author: Author; } -expectAssignable>({ +expectAssignable>({ bestBook: { title: 'book title', author: { @@ -40,77 +45,77 @@ expectNotType>({ //////////// Filter // Depth of 1 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.title': 23 }); // Depth of 2 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.name': 23 }); // Depth of 3 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.title': 23 }); // Depth of 4 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.author.name': 23 }); // Depth of 5 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.author.bestBook.title': 23 }); // Depth of 6 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.author.bestBook.author.name': 23 }); // Depth of 7 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.author.bestBook.author.bestBook.title': 23 }); // Depth of 8 does **not** have type checking -expectAssignable>({ +expectAssignable>({ 'bestBook.author.bestBook.author.bestBook.author.bestBook.author.name': 23 }); //////////// UpdateFilter // Depth of 1 has type checking -expectNotAssignable>({ +expectNotAssignable>({ $set: { 'bestBook.title': 23 } }); // Depth of 2 has type checking -expectNotAssignable>({ +expectAssignable>({ $set: { 'bestBook.author.name': 23 } }); // Depth of 3 has type checking -expectNotAssignable>({ +expectAssignable>({ $set: { 'bestBook.author.bestBook.title': 23 } }); // Depth of 4 has type checking -expectNotAssignable>({ +expectAssignable>({ $set: { 'bestBook.author.bestBook.author.name': 23 } }); // Depth of 5 has type checking -expectNotAssignable>({ +expectAssignable>({ $set: { 'bestBook.author.bestBook.author.bestBook.title': 23 } }); // Depth of 6 has type checking -expectNotAssignable>({ +expectAssignable>({ $set: { 'bestBook.author.bestBook.author.bestBook.author.name': 23 } }); // Depth of 7 has type checking -expectNotAssignable>({ +expectAssignable>({ $set: { 'bestBook.author.bestBook.author.bestBook.author.bestBook.title': 23 } @@ -132,11 +137,6 @@ interface RecursiveButNotReally { } declare const recursiveButNotReallyCollection: Collection; -expectError( - recursiveButNotReallyCollection.find({ - 'a.a': 'asdf' - }) -); recursiveButNotReallyCollection.find({ 'a.a': 2 }); @@ -237,17 +237,6 @@ interface Directory { } declare const recursiveSchemaWithArray: Collection; -expectError( - recursiveSchemaWithArray.findOne({ - 'branches.0.id': 'hello' - }) -); - -expectError( - recursiveSchemaWithArray.findOne({ - 'branches.0.directories.0.id': 'hello' - }) -); // type safety breaks after the first // level of nested types @@ -297,12 +286,12 @@ type D = { a: A; }; -expectAssignable>({ +expectAssignable>({ 'b.c.d.a.b.c.d.a.b.name': 'a' }); // Beyond the depth supported, there is no type checking -expectAssignable>({ +expectAssignable>({ 'b.c.d.a.b.c.d.a.b.c.name': 3 }); diff --git a/test/types/community/collection/updateX.test-d.ts b/test/types/community/collection/updateX.test-d.ts index 09c8744ce70..ac0d9e5966d 100644 --- a/test/types/community/collection/updateX.test-d.ts +++ b/test/types/community/collection/updateX.test-d.ts @@ -3,6 +3,7 @@ import { expectAssignable, expectError, expectNotAssignable, expectNotType } fro import type { AddToSetOperators, ArrayOperator, + DotNotationUpdateFilter, MatchKeysAndValues, PullAllOperator, PullOperator, @@ -105,7 +106,9 @@ interface TestModel { } const collectionTType = db.collection('test.update'); -function buildUpdateFilter(updateQuery: UpdateFilter): UpdateFilter { +function buildUpdateFilter( + updateQuery: UpdateFilter +): DotNotationUpdateFilter { return updateQuery; } @@ -214,13 +217,12 @@ expectAssignable>({ $set: { 'subInterfaceField.nestedObj expectAssignable>({ $set: { 'subInterfaceField.nestedObject': { a: '1', b: '2' } } }); -expectError>({ +expectError>({ $set: { 'subInterfaceField.nestedObject': { a: '1' } } }); -expectError>({ +expectError>({ $set: { 'subInterfaceField.nestedObject': { a: 1, b: '2' } } }); -expectError(buildUpdateFilter({ $set: { 'subInterfaceField.field2': 2 } })); // NODE-3875 introduced intersection with Document to the MatchKeysAndValues so this no longer errors expectAssignable>({ $set: { 'unknown.field': null } }); @@ -231,7 +233,6 @@ expectAssignable>({ $set: { 'numberArray.$[]': 1000.2 } expectAssignable>({ $set: { 'subInterfaceArray.$.field3': 40 } }); expectAssignable>({ $set: { 'subInterfaceArray.$[bla].field3': 40 } }); expectAssignable>({ $set: { 'subInterfaceArray.$[].field3': 1000.2 } }); -expectError(buildUpdateFilter({ $set: { 'numberArray.$': '20' } })); expectAssignable>({ $setOnInsert: { numberField: 1 } }); expectAssignable>({ @@ -243,7 +244,6 @@ expectAssignable>({ $setOnInsert: { longField: Long.from expectAssignable>({ $setOnInsert: { stringField: 'a' } }); expectError(buildUpdateFilter({ $setOnInsert: { stringField: 123 } })); expectAssignable>({ $setOnInsert: { 'subInterfaceField.field1': '2' } }); -expectError(buildUpdateFilter({ $setOnInsert: { 'subInterfaceField.field2': 2 } })); // NODE-3875 introduced intersection with Document to the MatchKeysAndValues so this no longer errors expectAssignable>({ $setOnInsert: { 'unknown.field': null } }); From 97f2eb978fc7fbd63c94a704e3c1bb8d2b1d5a43 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 11 Jan 2023 21:22:24 -0500 Subject: [PATCH 02/10] docs: update migration guide --- etc/notes/CHANGES_5.0.0.md | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/etc/notes/CHANGES_5.0.0.md b/etc/notes/CHANGES_5.0.0.md index 048e2bbef02..204a66aabec 100644 --- a/etc/notes/CHANGES_5.0.0.md +++ b/etc/notes/CHANGES_5.0.0.md @@ -16,6 +16,53 @@ The following is a detailed collection of the changes in the major v5 release of ## Changes +### Dot Notation Typescript Support Removed By Default + +**NOTE** This version only removes our **Typescript** compile-time support for dot notation in queries. + +Version 4.3.0 introduced Typescript support for dot notation in filter predicates. For example: + +```typescript +interface Schema { + user: { + name: string + } +} + +declare const collection: Collection; +// compiles pre-v4.3.0, fails in v4.3.0+ +collection.find({ 'user.name': 4 }) +``` + +This change caused many problems for users, including slow compilation times and compile errors for +valid dot notation queries. + +Driver 5.0 removes type checking on filter predicates. The preceding example compile will compile with +driver v5. + +#### Dot Notation Helper Types Exported + +Although we removed support for type checking on dot notation filters by default, we now export these types. +These helper types can be used for type checking. We export the `DotNotationUpdateFilter` and the `DotNotationFilter` +types for type safety in updates and finds. + +To use one of the new types, simply create a predicate that uses dot notation and assign it the type of `DotNotationFilter`. +```typescript +interface Schema { + user: { + name: string + } +} + +declare const collection: Collection; + +// fails to compile, 4 is not assignable to type "string" +const filterPredicate: DotNotationFilter = { 'user.name': 4 }; +collection.find(filterPredicate); +``` + +**NOTE** These types are also now marked experimental and can be changed at any time. + ### `Collection.mapReduce()` helper removed The `mapReduce` helper has been removed from the `Collection` class. The `mapReduce` operation has been From 483bac9c48aa4cd1ce4563fcf59e62f76a11b311 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 12 Jan 2023 08:04:44 -0500 Subject: [PATCH 03/10] chore: fix lint --- src/collection.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/collection.ts b/src/collection.ts index 5babeaa8edc..75d597aa639 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -86,7 +86,6 @@ import { Callback, checkCollectionName, DEFAULT_PK_FACTORY, - emitWarningOnce, MongoDBNamespace, normalizeHintField, resolveOptions From 55b37874b1d8a268e61d3217cb57f1d6583078e6 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 12 Jan 2023 09:38:11 -0500 Subject: [PATCH 04/10] Update etc/notes/CHANGES_5.0.0.md Co-authored-by: Durran Jordan --- etc/notes/CHANGES_5.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/notes/CHANGES_5.0.0.md b/etc/notes/CHANGES_5.0.0.md index 204a66aabec..f7a41311f5f 100644 --- a/etc/notes/CHANGES_5.0.0.md +++ b/etc/notes/CHANGES_5.0.0.md @@ -37,7 +37,7 @@ collection.find({ 'user.name': 4 }) This change caused many problems for users, including slow compilation times and compile errors for valid dot notation queries. -Driver 5.0 removes type checking on filter predicates. The preceding example compile will compile with +Driver 5.0 removes type checking on filter predicates. The preceding example will compile with driver v5. #### Dot Notation Helper Types Exported From c4a9f856f0a1976bd90e089d50ed28fc0415fbeb Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 18 Jan 2023 14:15:09 -0500 Subject: [PATCH 05/10] chore: rename types --- src/index.ts | 6 ++-- src/mongo_types.ts | 19 +++++++------ .../collection/recursive-types.test-d.ts | 28 +++++++++---------- .../community/collection/updateX.test-d.ts | 8 +++--- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/index.ts b/src/index.ts index b52316dff9a..dadb64da5f5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -309,9 +309,6 @@ export type { BitwiseFilter, BSONTypeAlias, Condition, - DotNotationFilter, - DotNotationMatchKeysAndValues, - DotNotationUpdateFilter, EnhancedOmit, Filter, FilterOperations, @@ -341,6 +338,9 @@ export type { RootFilterOperators, SchemaMember, SetFields, + StrictFilter, + StrictMatchKeysAndValues, + StrictUpdateFilter, UpdateFilter, WithId, WithoutId diff --git a/src/mongo_types.ts b/src/mongo_types.ts index c611889f5f4..16f5740e95d 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -530,7 +530,7 @@ export type NestedPathsOfType = KeysOfAType< * @public * @experimental */ -export type DotNotationFilter = +export type StrictFilter = | Partial | ({ [Property in Join, []>, '.'>]?: Condition< @@ -542,19 +542,19 @@ export type DotNotationFilter = * @public * @experimental */ -export type DotNotationUpdateFilter = { +export type StrictUpdateFilter = { $currentDate?: OnlyFieldsOfType< TSchema, Date | Timestamp, true | { $type: 'date' | 'timestamp' } >; $inc?: OnlyFieldsOfType; - $min?: DotNotationMatchKeysAndValues; - $max?: DotNotationMatchKeysAndValues; + $min?: StrictMatchKeysAndValues; + $max?: StrictMatchKeysAndValues; $mul?: OnlyFieldsOfType; $rename?: Record; - $set?: DotNotationMatchKeysAndValues; - $setOnInsert?: DotNotationMatchKeysAndValues; + $set?: StrictMatchKeysAndValues; + $setOnInsert?: StrictMatchKeysAndValues; $unset?: OnlyFieldsOfType; $addToSet?: SetFields; $pop?: OnlyFieldsOfType, 1 | -1>; @@ -568,8 +568,11 @@ export type DotNotationUpdateFilter = { >; } & Document; -/** @public */ -export type DotNotationMatchKeysAndValues = Readonly< +/** + * @public + * @experimental + */ +export type StrictMatchKeysAndValues = Readonly< { [Property in Join, '.'>]?: PropertyType; } & { diff --git a/test/types/community/collection/recursive-types.test-d.ts b/test/types/community/collection/recursive-types.test-d.ts index e90528d9799..42d90105b8e 100644 --- a/test/types/community/collection/recursive-types.test-d.ts +++ b/test/types/community/collection/recursive-types.test-d.ts @@ -2,8 +2,8 @@ import { expectAssignable, expectError, expectNotAssignable, expectNotType } fro import type { Collection, - DotNotationFilter, - DotNotationUpdateFilter, + StrictFilter, + StrictUpdateFilter, UpdateFilter } from '../../../../src'; @@ -20,7 +20,7 @@ interface Book { author: Author; } -expectAssignable>({ +expectAssignable>({ bestBook: { title: 'book title', author: { @@ -45,41 +45,41 @@ expectNotType>({ //////////// Filter // Depth of 1 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.title': 23 }); // Depth of 2 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.name': 23 }); // Depth of 3 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.title': 23 }); // Depth of 4 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.author.name': 23 }); // Depth of 5 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.author.bestBook.title': 23 }); // Depth of 6 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.author.bestBook.author.name': 23 }); // Depth of 7 has type checking -expectNotAssignable>({ +expectNotAssignable>({ 'bestBook.author.bestBook.author.bestBook.author.bestBook.title': 23 }); // Depth of 8 does **not** have type checking -expectAssignable>({ +expectAssignable>({ 'bestBook.author.bestBook.author.bestBook.author.bestBook.author.name': 23 }); //////////// UpdateFilter // Depth of 1 has type checking -expectNotAssignable>({ +expectNotAssignable>({ $set: { 'bestBook.title': 23 } @@ -286,12 +286,12 @@ type D = { a: A; }; -expectAssignable>({ +expectAssignable>({ 'b.c.d.a.b.c.d.a.b.name': 'a' }); // Beyond the depth supported, there is no type checking -expectAssignable>({ +expectAssignable>({ 'b.c.d.a.b.c.d.a.b.c.name': 3 }); diff --git a/test/types/community/collection/updateX.test-d.ts b/test/types/community/collection/updateX.test-d.ts index ac0d9e5966d..0d2609318b7 100644 --- a/test/types/community/collection/updateX.test-d.ts +++ b/test/types/community/collection/updateX.test-d.ts @@ -3,7 +3,7 @@ import { expectAssignable, expectError, expectNotAssignable, expectNotType } fro import type { AddToSetOperators, ArrayOperator, - DotNotationUpdateFilter, + StrictUpdateFilter, MatchKeysAndValues, PullAllOperator, PullOperator, @@ -108,7 +108,7 @@ const collectionTType = db.collection('test.update'); function buildUpdateFilter( updateQuery: UpdateFilter -): DotNotationUpdateFilter { +): StrictUpdateFilter { return updateQuery; } @@ -217,10 +217,10 @@ expectAssignable>({ $set: { 'subInterfaceField.nestedObj expectAssignable>({ $set: { 'subInterfaceField.nestedObject': { a: '1', b: '2' } } }); -expectError>({ +expectError>({ $set: { 'subInterfaceField.nestedObject': { a: '1' } } }); -expectError>({ +expectError>({ $set: { 'subInterfaceField.nestedObject': { a: 1, b: '2' } } }); From ab509adb562f20d576d01635fa6fecd41be28c90 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 18 Jan 2023 14:18:17 -0500 Subject: [PATCH 06/10] chore: fix lint --- test/types/community/collection/recursive-types.test-d.ts | 7 +------ test/types/community/collection/updateX.test-d.ts | 6 ++---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/test/types/community/collection/recursive-types.test-d.ts b/test/types/community/collection/recursive-types.test-d.ts index 42d90105b8e..388bfc893a8 100644 --- a/test/types/community/collection/recursive-types.test-d.ts +++ b/test/types/community/collection/recursive-types.test-d.ts @@ -1,11 +1,6 @@ import { expectAssignable, expectError, expectNotAssignable, expectNotType } from 'tsd'; -import type { - Collection, - StrictFilter, - StrictUpdateFilter, - UpdateFilter -} from '../../../../src'; +import type { Collection, StrictFilter, StrictUpdateFilter, UpdateFilter } from '../../../../src'; /** * mutually recursive types are not supported and will not get type safety diff --git a/test/types/community/collection/updateX.test-d.ts b/test/types/community/collection/updateX.test-d.ts index 0d2609318b7..9107db45add 100644 --- a/test/types/community/collection/updateX.test-d.ts +++ b/test/types/community/collection/updateX.test-d.ts @@ -3,12 +3,12 @@ import { expectAssignable, expectError, expectNotAssignable, expectNotType } fro import type { AddToSetOperators, ArrayOperator, - StrictUpdateFilter, MatchKeysAndValues, PullAllOperator, PullOperator, PushOperator, SetFields, + StrictUpdateFilter, UpdateFilter } from '../../../mongodb'; import { @@ -106,9 +106,7 @@ interface TestModel { } const collectionTType = db.collection('test.update'); -function buildUpdateFilter( - updateQuery: UpdateFilter -): StrictUpdateFilter { +function buildUpdateFilter(updateQuery: UpdateFilter): StrictUpdateFilter { return updateQuery; } From 7cc0c10bc2cd2079b9e7d250ba0ec31ad4c9a167 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 19 Jan 2023 10:33:40 -0500 Subject: [PATCH 07/10] Apply suggestions from code review Co-authored-by: Neal Beeken --- etc/notes/CHANGES_5.0.0.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/etc/notes/CHANGES_5.0.0.md b/etc/notes/CHANGES_5.0.0.md index f7a41311f5f..3f77cee6d3a 100644 --- a/etc/notes/CHANGES_5.0.0.md +++ b/etc/notes/CHANGES_5.0.0.md @@ -18,7 +18,7 @@ The following is a detailed collection of the changes in the major v5 release of ### Dot Notation Typescript Support Removed By Default -**NOTE** This version only removes our **Typescript** compile-time support for dot notation in queries. +**NOTE** This is a **Typescript compile-time only** change. Dot notation in filters sent to MongoDB still work the same. Version 4.3.0 introduced Typescript support for dot notation in filter predicates. For example: @@ -43,10 +43,10 @@ driver v5. #### Dot Notation Helper Types Exported Although we removed support for type checking on dot notation filters by default, we now export these types. -These helper types can be used for type checking. We export the `DotNotationUpdateFilter` and the `DotNotationFilter` +These helper types can be used for type checking. We export the `StrictUpdateFilter` and the `StrictFilter` types for type safety in updates and finds. -To use one of the new types, simply create a predicate that uses dot notation and assign it the type of `DotNotationFilter`. +To use one of the new types, simply create a predicate that uses dot notation and assign it the type of `StrictFilter`. ```typescript interface Schema { user: { @@ -57,7 +57,7 @@ interface Schema { declare const collection: Collection; // fails to compile, 4 is not assignable to type "string" -const filterPredicate: DotNotationFilter = { 'user.name': 4 }; +const filterPredicate: StrictFilter = { 'user.name': 4 }; collection.find(filterPredicate); ``` From 77112b676e2464b6a3faa5c7de8bd67a1f0d298b Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 19 Jan 2023 16:57:30 -0500 Subject: [PATCH 08/10] Apply suggestions from code review Co-authored-by: Daria Pardue --- etc/notes/CHANGES_5.0.0.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/etc/notes/CHANGES_5.0.0.md b/etc/notes/CHANGES_5.0.0.md index a707ccf8366..c21259b2a07 100644 --- a/etc/notes/CHANGES_5.0.0.md +++ b/etc/notes/CHANGES_5.0.0.md @@ -18,7 +18,7 @@ The following is a detailed collection of the changes in the major v5 release of ### Dot Notation Typescript Support Removed By Default -**NOTE** This is a **Typescript compile-time only** change. Dot notation in filters sent to MongoDB still work the same. +**NOTE** This is a **Typescript compile-time only** change. Dot notation in filters sent to MongoDB will still work the same. Version 4.3.0 introduced Typescript support for dot notation in filter predicates. For example: @@ -34,15 +34,17 @@ declare const collection: Collection; collection.find({ 'user.name': 4 }) ``` -This change caused many problems for users, including slow compilation times and compile errors for -valid dot notation queries. +This change caused a number of problems for users, including slow compilation times and compile errors for +valid dot notation queries. While we have tried to mitigate this issue as much as possible +in v4, ultimately we do not believe that this feature is fully production ready for all use cases. Driver 5.0 removes type checking on filter predicates. The preceding example will compile with driver v5. #### Dot Notation Helper Types Exported -Although we removed support for type checking on dot notation filters by default, we now export these types. +Although we removed support for type checking on dot notation filters by default, we have preserved the +corresponding types in an experimental capacity. These helper types can be used for type checking. We export the `StrictUpdateFilter` and the `StrictFilter` types for type safety in updates and finds. @@ -61,7 +63,7 @@ const filterPredicate: StrictFilter = { 'user.name': 4 }; collection.find(filterPredicate); ``` -**NOTE** These types are also now marked experimental and can be changed at any time. +**NOTE** As an experimental feature, these types can change at any time and are not recommended for production settings. ### `Collection.mapReduce()` helper removed From 8e3101c17b1de9def0eef91f560a44ec1bfdcea9 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 19 Jan 2023 16:58:05 -0500 Subject: [PATCH 09/10] Update etc/notes/CHANGES_5.0.0.md --- etc/notes/CHANGES_5.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/notes/CHANGES_5.0.0.md b/etc/notes/CHANGES_5.0.0.md index c21259b2a07..b30b961554c 100644 --- a/etc/notes/CHANGES_5.0.0.md +++ b/etc/notes/CHANGES_5.0.0.md @@ -38,7 +38,7 @@ This change caused a number of problems for users, including slow compilation ti valid dot notation queries. While we have tried to mitigate this issue as much as possible in v4, ultimately we do not believe that this feature is fully production ready for all use cases. -Driver 5.0 removes type checking on filter predicates. The preceding example will compile with +Driver 5.0 removes type checking for dot notation on filter predicates. The preceding example will compile with driver v5. #### Dot Notation Helper Types Exported From 46b3b1f8e9b814a6f831ed02eb8cbb824c6c3c9f Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 19 Jan 2023 16:58:30 -0500 Subject: [PATCH 10/10] Update etc/notes/CHANGES_5.0.0.md --- etc/notes/CHANGES_5.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/notes/CHANGES_5.0.0.md b/etc/notes/CHANGES_5.0.0.md index b30b961554c..6175eb8ee3a 100644 --- a/etc/notes/CHANGES_5.0.0.md +++ b/etc/notes/CHANGES_5.0.0.md @@ -38,7 +38,7 @@ This change caused a number of problems for users, including slow compilation ti valid dot notation queries. While we have tried to mitigate this issue as much as possible in v4, ultimately we do not believe that this feature is fully production ready for all use cases. -Driver 5.0 removes type checking for dot notation on filter predicates. The preceding example will compile with +Driver 5.0 removes type checking for dot notation in filter predicates. The preceding example will compile with driver v5. #### Dot Notation Helper Types Exported