From b0e17e8c2272de00e644cff761be6447c57944dc Mon Sep 17 00:00:00 2001 From: Valentin Agachi Date: Mon, 6 Sep 2021 18:50:04 +0200 Subject: [PATCH 1/7] feat: support dot-notation attributes in Filter --- src/mongo_types.ts | 47 ++++++++++++++++- .../collection/filterQuery.test-d.ts | 50 +++++++++++++++---- 2 files changed, 86 insertions(+), 11 deletions(-) diff --git a/src/mongo_types.ts b/src/mongo_types.ts index fd06ae7831..61fd1a89c2 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -57,7 +57,7 @@ export type WithoutId = Omit; /** A MongoDB filter can be some portion of the schema or a set of operators @public */ export type Filter = { - [P in keyof WithId]?: Condition[P]>; + [P in Join>, '.'>]?: Condition, P>>; } & RootFilterOperators>; /** @public */ @@ -423,3 +423,48 @@ export class TypedEventEmitter extends EventEm /** @public */ export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> {} + +/** + * Helper types for dot-notation filter attributes + */ + +/** @public */ +export type Join = T extends [] + ? '' + : T extends [string | number] + ? `${T[0]}` + : T extends [string | number, ...infer R] + ? `${T[0]}${D}${Join}` + : string | number; + +/** @public */ +export type PropertyType = string extends Property + ? unknown + : Property extends keyof Type + ? Type[Property] + : Property extends `${infer Key}.${infer Rest}` + ? Key extends `${number}` + ? Type extends Array + ? PropertyType + : Type extends ReadonlyArray + ? PropertyType + : unknown + : Key extends keyof Type + ? PropertyType + : unknown + : unknown; + +// We dont't support nested circular references +/** @public */ +export type NestedPaths = Type extends string | number | boolean | Date | ObjectId + ? [] + : Type extends Array + ? [number, ...NestedPaths] + : Type extends ReadonlyArray + ? [number, ...NestedPaths] + : // eslint-disable-next-line @typescript-eslint/ban-types + Type extends object + ? { + [Key in Extract]: [Key, ...NestedPaths]; + }[Extract] + : []; diff --git a/test/types/community/collection/filterQuery.test-d.ts b/test/types/community/collection/filterQuery.test-d.ts index 06d337e98e..aba5ae895c 100644 --- a/test/types/community/collection/filterQuery.test-d.ts +++ b/test/types/community/collection/filterQuery.test-d.ts @@ -16,6 +16,11 @@ const db = client.db('test'); * Test the generic Filter using collection.find() method */ +interface HumanModel { + _id: ObjectId; + name: string; +} + // a collection model for all possible MongoDB BSON types and TypeScript types interface PetModel { _id: ObjectId; // ObjectId field @@ -24,14 +29,28 @@ interface PetModel { age: number; // number field type: 'dog' | 'cat' | 'fish'; // union field isCute: boolean; // boolean field - bestFriend?: PetModel; // object field (Embedded/Nested Documents) + bestFriend?: HumanModel; // object field (Embedded/Nested Documents) createdAt: Date; // date field treats: string[]; // array of string playTimePercent: Decimal128; // bson Decimal128 type - readonly friends?: ReadonlyArray; // readonly array of objects - playmates?: PetModel[]; // writable array of objects + readonly friends?: ReadonlyArray; // readonly array of objects + playmates?: HumanModel[]; // writable array of objects + // Object with multiple nested levels + meta?: { + updatedAt?: Date; + deep?: { + nested?: { + level?: number; + }; + }; + }; } +const john = { + _id: new ObjectId('577fa2d90c4cc47e31cf4b6a'), + name: 'John' +}; + const spot = { _id: new ObjectId('577fa2d90c4cc47e31cf4b6f'), name: 'Spot', @@ -83,14 +102,29 @@ expectNotType>({ age: [23, 43] }); /// it should query __nested document__ fields only by exact match // TODO: we currently cannot enforce field order but field order is important for mongo -await collectionT.find({ bestFriend: spot }).toArray(); +await collectionT.find({ bestFriend: john }).toArray(); /// nested documents query should contain all required fields -expectNotType>({ bestFriend: { family: 'Andersons' } }); +expectNotType>({ bestFriend: { name: 'Andersons' } }); /// it should not accept wrong types for nested document fields expectNotType>({ bestFriend: 21 }); expectNotType>({ bestFriend: 'Andersons' }); expectNotType>({ bestFriend: [spot] }); -expectNotType>({ bestFriend: [{ family: 'Andersons' }] }); +expectNotType>({ bestFriend: [{ name: 'Andersons' }] }); + +/// it should query __nested document__ fields using dot-notation +collectionT.find({ 'meta.updatedAt': new Date() }); +collectionT.find({ 'meta.deep.nested.level': 123 }); +collectionT.find({ 'friends.0.name': 'John' }); +collectionT.find({ 'playmates.0.name': 'John' }); +/// it should not accept wrong types for nested document fields +expectNotType>({ 'meta.updatedAt': 123 }); +expectNotType>({ 'meta.updatedAt': true }); +expectNotType>({ 'meta.updatedAt': 'now' }); +expectNotType>({ 'meta.deep.nested.level': '123' }); +expectNotType>({ 'meta.deep.nested.level': true }); +expectNotType>({ 'meta.deep.nested.level': new Date() }); +expectNotType>({ 'friends.0.name': 123 }); +expectNotType>({ 'playmates.0.name': 123 }); /// it should query __array__ fields by exact match await collectionT.find({ treats: ['kibble', 'bone'] }).toArray(); @@ -232,7 +266,3 @@ await collectionT.find({ playmates: { $elemMatch: { name: 'MrMeow' } } }).toArra expectNotType>({ name: { $all: ['world', 'world'] } }); expectNotType>({ age: { $elemMatch: [1, 2] } }); expectNotType>({ type: { $size: 2 } }); - -// dot key case that shows it is assignable even when the referenced key is the wrong type -expectAssignable>({ 'bestFriend.name': 23 }); // using dot notation permits any type for the key -expectNotType>({ bestFriend: { name: 23 } }); From f68f71b2f26db61c0de9ec64380d6466cb36911f Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 16 Nov 2021 10:33:38 -0500 Subject: [PATCH 2/7] test: add some additional tests with comments --- .../collection/filterQuery.test-d.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/types/community/collection/filterQuery.test-d.ts b/test/types/community/collection/filterQuery.test-d.ts index aba5ae895c..88d990169e 100644 --- a/test/types/community/collection/filterQuery.test-d.ts +++ b/test/types/community/collection/filterQuery.test-d.ts @@ -1,4 +1,4 @@ -import { BSONRegExp, Decimal128, ObjectId } from 'bson'; +import { BSONRegExp, Decimal128, Long, ObjectId } from 'bson'; import { expectAssignable, expectNotType, expectType } from 'tsd'; import { Filter, MongoClient, WithId } from '../../../../src'; @@ -31,6 +31,7 @@ interface PetModel { isCute: boolean; // boolean field bestFriend?: HumanModel; // object field (Embedded/Nested Documents) createdAt: Date; // date field + numOfPats: Long; // long field treats: string[]; // array of string playTimePercent: Decimal128; // bson Decimal128 type readonly friends?: ReadonlyArray; // readonly array of objects @@ -39,6 +40,7 @@ interface PetModel { meta?: { updatedAt?: Date; deep?: { + nestedArray: number[]; nested?: { level?: number; }; @@ -59,6 +61,7 @@ const spot = { type: 'dog' as const, isCute: true, createdAt: new Date(), + numOfPats: Long.fromBigInt(100000000n), treats: ['kibble', 'bone'], playTimePercent: new Decimal128('0.999999') }; @@ -114,8 +117,20 @@ expectNotType>({ bestFriend: [{ name: 'Andersons' }] }); /// it should query __nested document__ fields using dot-notation collectionT.find({ 'meta.updatedAt': new Date() }); collectionT.find({ 'meta.deep.nested.level': 123 }); +collectionT.find({ meta: { deep: { nested: { level: 123 } } } }); // no impact on actual nesting collectionT.find({ 'friends.0.name': 'John' }); collectionT.find({ 'playmates.0.name': 'John' }); + +// There's an issue with the special BSON types +collectionT.find({ 'numOfPats.__isLong__': true }); +collectionT.find({ numOfPats: Long.fromBigInt(2n) }); +collectionT.find({ 'playTimePercent.bytes.BYTES_PER_ELEMENT': 1 }); +collectionT.find({ playTimePercent: new Decimal128('123.2') }); + +// works with some extreme indexes +collectionT.find({ 'friends.4294967295.name': 'John' }); +collectionT.find({ 'friends.999999999999999999999999999999999999.name': 'John' }); + /// it should not accept wrong types for nested document fields expectNotType>({ 'meta.updatedAt': 123 }); expectNotType>({ 'meta.updatedAt': true }); @@ -126,6 +141,10 @@ expectNotType>({ 'meta.deep.nested.level': new Date() }); expectNotType>({ 'friends.0.name': 123 }); expectNotType>({ 'playmates.0.name': 123 }); +// Nested arrays aren't checked +expectType>({ 'meta.deep.nestedArray.0': 'not a number' }); +expectNotType>({ 'meta.deep.nestedArray.23': 'not a number' }); + /// it should query __array__ fields by exact match await collectionT.find({ treats: ['kibble', 'bone'] }).toArray(); /// it should query __array__ fields by element type From 6786a3efc51824089d3fad6d92cef5d6a88b4212 Mon Sep 17 00:00:00 2001 From: Valentin Agachi Date: Tue, 16 Nov 2021 18:05:38 +0100 Subject: [PATCH 3/7] fix: address PR feedback --- src/mongo_types.ts | 24 ++++++++++++++----- .../collection/filterQuery.test-d.ts | 12 ++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/mongo_types.ts b/src/mongo_types.ts index 61fd1a89c2..10028e9ffc 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -442,11 +442,13 @@ export type PropertyType = string extends Propert ? unknown : Property extends keyof Type ? Type[Property] + : Property extends `${number}` + ? Type extends ReadonlyArray + ? ArrayType + : unknown : Property extends `${infer Key}.${infer Rest}` ? Key extends `${number}` - ? Type extends Array - ? PropertyType - : Type extends ReadonlyArray + ? Type extends ReadonlyArray ? PropertyType : unknown : Key extends keyof Type @@ -456,10 +458,20 @@ export type PropertyType = string extends Propert // We dont't support nested circular references /** @public */ -export type NestedPaths = Type extends string | number | boolean | Date | ObjectId +export type NestedPaths = Type extends + | string + | number + | boolean + | BSONRegExp + | Binary + | Date + | Decimal128 + | Double + | Int32 + | Long + | ObjectId + | Timestamp ? [] - : Type extends Array - ? [number, ...NestedPaths] : Type extends ReadonlyArray ? [number, ...NestedPaths] : // eslint-disable-next-line @typescript-eslint/ban-types diff --git a/test/types/community/collection/filterQuery.test-d.ts b/test/types/community/collection/filterQuery.test-d.ts index 88d990169e..83fd48ac3d 100644 --- a/test/types/community/collection/filterQuery.test-d.ts +++ b/test/types/community/collection/filterQuery.test-d.ts @@ -120,11 +120,11 @@ collectionT.find({ 'meta.deep.nested.level': 123 }); collectionT.find({ meta: { deep: { nested: { level: 123 } } } }); // no impact on actual nesting collectionT.find({ 'friends.0.name': 'John' }); collectionT.find({ 'playmates.0.name': 'John' }); +// supports arrays with primitive types +collectionT.find({ 'treats.0': 'bone' }); -// There's an issue with the special BSON types -collectionT.find({ 'numOfPats.__isLong__': true }); +// Handle special BSON types collectionT.find({ numOfPats: Long.fromBigInt(2n) }); -collectionT.find({ 'playTimePercent.bytes.BYTES_PER_ELEMENT': 1 }); collectionT.find({ playTimePercent: new Decimal128('123.2') }); // works with some extreme indexes @@ -140,10 +140,12 @@ expectNotType>({ 'meta.deep.nested.level': true }); expectNotType>({ 'meta.deep.nested.level': new Date() }); expectNotType>({ 'friends.0.name': 123 }); expectNotType>({ 'playmates.0.name': 123 }); +expectNotType>({ 'treats.0': 123 }); +expectNotType>({ 'numOfPats.__isLong__': true }); +expectNotType>({ 'playTimePercent.bytes.BYTES_PER_ELEMENT': 1 }); // Nested arrays aren't checked -expectType>({ 'meta.deep.nestedArray.0': 'not a number' }); -expectNotType>({ 'meta.deep.nestedArray.23': 'not a number' }); +expectNotType>({ 'meta.deep.nestedArray.0': 'not a number' }); /// it should query __array__ fields by exact match await collectionT.find({ treats: ['kibble', 'bone'] }).toArray(); From 80472831d98b0a62a38fe7027381364bff00d8c5 Mon Sep 17 00:00:00 2001 From: Valentin Agachi Date: Mon, 22 Nov 2021 15:53:46 +0100 Subject: [PATCH 4/7] fix: TS 4.5 fixes --- src/mongo_types.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mongo_types.ts b/src/mongo_types.ts index 10028e9ffc..44acfe955c 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -57,7 +57,9 @@ export type WithoutId = Omit; /** A MongoDB filter can be some portion of the schema or a set of operators @public */ export type Filter = { - [P in Join>, '.'>]?: Condition, P>>; + [Property in Join>, '.'>]?: Condition< + PropertyType, Property> + >; } & RootFilterOperators>; /** @public */ @@ -435,7 +437,7 @@ export type Join = T extends [] ? `${T[0]}` : T extends [string | number, ...infer R] ? `${T[0]}${D}${Join}` - : string | number; + : string; /** @public */ export type PropertyType = string extends Property From 903442afd48e662da15e6398d623cb0bc5764b07 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 3 Dec 2021 15:12:34 -0500 Subject: [PATCH 5/7] fix: typescript linting bump one minor version --- .evergreen/run-checks.sh | 16 ++++++++++------ README.md | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.evergreen/run-checks.sh b/.evergreen/run-checks.sh index 318023e3ab..944b4b36e7 100644 --- a/.evergreen/run-checks.sh +++ b/.evergreen/run-checks.sh @@ -20,12 +20,16 @@ npm run check:lint npm run check:unit -echo "Typescript $(npx tsc -v)" +export TSC="./node_modules/typescript/bin/tsc" + +echo "Typescript $($TSC -v)" # check resolution uses the default latest types -echo "import * as mdb from '.'" > file.ts && npx tsc --noEmit --traceResolution file.ts | grep 'mongodb.d.ts' && rm file.ts +echo "import * as mdb from '.'" > file.ts && $TSC --noEmit --traceResolution file.ts | grep 'mongodb.d.ts' && rm file.ts -npm i --no-save typescript@4.0.2 # there is no 4.0.0 -echo "Typescript $(npx tsc -v)" -npx tsc --noEmit mongodb.ts34.d.ts +npm i --no-save typescript@4.1.6 +echo "Typescript $($TSC -v)" +$TSC --noEmit mongodb.ts34.d.ts # check that resolution uses the downleveled types -echo "import * as mdb from '.'" > file.ts && npx tsc --noEmit --traceResolution file.ts | grep 'mongodb.ts34.d.ts' && rm file.ts +echo "import * as mdb from '.'" > file.ts && $TSC --noEmit --traceResolution file.ts | grep 'mongodb.ts34.d.ts' && rm file.ts + +rm -f file.ts diff --git a/README.md b/README.md index 6832698678..560f628f63 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ For version compatibility matrices, please refer to the following links: #### Typescript Version -We recommend using the latest version of typescript, however we do provide a [downleveled](https://github.com/sandersn/downlevel-dts#readme) version of the type definitions that we test compiling against `typescript@4.0.2`. +We recommend using the latest version of typescript, however we do provide a [downleveled](https://github.com/sandersn/downlevel-dts#readme) version of the type definitions that we test compiling against `typescript@4.1.6`. Since typescript [does not restrict breaking changes to major versions](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes) we consider this support best effort. If you run into any unexpected compiler failures please let us know and we will do our best to correct it. From 70685e053384af818979b3d23e28d74f8e6190c7 Mon Sep 17 00:00:00 2001 From: Valentin Agachi Date: Thu, 16 Dec 2021 09:54:01 +0000 Subject: [PATCH 6/7] fix: add support for Map --- src/index.ts | 3 +++ src/mongo_types.ts | 6 +++++- test/types/community/collection/filterQuery.test-d.ts | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 609d2607df..1656b6261a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -283,9 +283,11 @@ export type { InferIdType, IntegerType, IsAny, + Join, KeysOfAType, KeysOfOtherType, MatchKeysAndValues, + NestedPaths, NotAcceptedFields, NumericType, OneOrMore, @@ -293,6 +295,7 @@ export type { OptionalId, Projection, ProjectionOperators, + PropertyType, PullAllOperator, PullOperator, PushOperator, diff --git a/src/mongo_types.ts b/src/mongo_types.ts index 44acfe955c..db4c38e382 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -454,7 +454,9 @@ export type PropertyType = string extends Propert ? PropertyType : unknown : Key extends keyof Type - ? PropertyType + ? Type[Key] extends Map + ? MapType + : PropertyType : unknown : unknown; @@ -476,6 +478,8 @@ export type NestedPaths = Type extends ? [] : Type extends ReadonlyArray ? [number, ...NestedPaths] + : Type extends Map + ? [string] : // eslint-disable-next-line @typescript-eslint/ban-types Type extends object ? { diff --git a/test/types/community/collection/filterQuery.test-d.ts b/test/types/community/collection/filterQuery.test-d.ts index 83fd48ac3d..d4c2014db4 100644 --- a/test/types/community/collection/filterQuery.test-d.ts +++ b/test/types/community/collection/filterQuery.test-d.ts @@ -36,6 +36,7 @@ interface PetModel { playTimePercent: Decimal128; // bson Decimal128 type readonly friends?: ReadonlyArray; // readonly array of objects playmates?: HumanModel[]; // writable array of objects + laps?: Map; // map field // Object with multiple nested levels meta?: { updatedAt?: Date; @@ -122,6 +123,7 @@ collectionT.find({ 'friends.0.name': 'John' }); collectionT.find({ 'playmates.0.name': 'John' }); // supports arrays with primitive types collectionT.find({ 'treats.0': 'bone' }); +collectionT.find({ 'laps.foo': 123 }); // Handle special BSON types collectionT.find({ numOfPats: Long.fromBigInt(2n) }); @@ -135,11 +137,12 @@ collectionT.find({ 'friends.999999999999999999999999999999999999.name': 'John' } expectNotType>({ 'meta.updatedAt': 123 }); expectNotType>({ 'meta.updatedAt': true }); expectNotType>({ 'meta.updatedAt': 'now' }); -expectNotType>({ 'meta.deep.nested.level': '123' }); +expectNotType>({ 'meta.deep.nested.level': 'string' }); expectNotType>({ 'meta.deep.nested.level': true }); expectNotType>({ 'meta.deep.nested.level': new Date() }); expectNotType>({ 'friends.0.name': 123 }); expectNotType>({ 'playmates.0.name': 123 }); +expectNotType>({ 'laps.foo': 'string' }); expectNotType>({ 'treats.0': 123 }); expectNotType>({ 'numOfPats.__isLong__': true }); expectNotType>({ 'playTimePercent.bytes.BYTES_PER_ELEMENT': 1 }); From e0996a70d1965984e996ac96cb33e222c4965bc8 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 17 Dec 2021 17:02:28 -0500 Subject: [PATCH 7/7] fix: simplify BSON type detection, add regex and function --- src/mongo_types.ts | 13 ++-- .../collection/filterQuery.test-d.ts | 67 +++++++++++++++++-- 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/mongo_types.ts b/src/mongo_types.ts index fef3594572..60564a87cf 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -483,15 +483,12 @@ export type NestedPaths = Type extends | string | number | boolean - | BSONRegExp - | Binary | Date - | Decimal128 - | Double - | Int32 - | Long - | ObjectId - | Timestamp + | RegExp + | Buffer + | Uint8Array + | ((...args: any[]) => any) + | { _bsontype: string } ? [] : Type extends ReadonlyArray ? [number, ...NestedPaths] diff --git a/test/types/community/collection/filterQuery.test-d.ts b/test/types/community/collection/filterQuery.test-d.ts index dc135f992b..53c83f586f 100644 --- a/test/types/community/collection/filterQuery.test-d.ts +++ b/test/types/community/collection/filterQuery.test-d.ts @@ -1,4 +1,15 @@ -import { BSONRegExp, Decimal128, Long, ObjectId } from 'bson'; +import { + Binary, + BSONRegExp, + BSONSymbol, + Code, + DBRef, + Decimal128, + Long, + MaxKey, + MinKey, + ObjectId +} from 'bson'; import { expectAssignable, expectError, expectNotType, expectType } from 'tsd'; import { Collection, Filter, MongoClient, WithId } from '../../../../src'; @@ -47,6 +58,17 @@ interface PetModel { }; }; }; + + binary: Binary; + code: Code; + minKey: MinKey; + maxKey: MaxKey; + dBRef: DBRef; + bSONSymbol: BSONSymbol; + + regex: RegExp; + + fn: (...args: any[]) => any; } const john = { @@ -64,7 +86,20 @@ const spot = { createdAt: new Date(), numOfPats: Long.fromBigInt(100000000n), treats: ['kibble', 'bone'], - playTimePercent: new Decimal128('0.999999') + playTimePercent: new Decimal128('0.999999'), + + binary: new Binary('', 2), + code: new Code(() => true), + minKey: new MinKey(), + maxKey: new MaxKey(), + dBRef: new DBRef('collection', new ObjectId()), + bSONSymbol: new BSONSymbol('hi'), + + regex: /a/, + + fn() { + return 'hi'; + } }; expectAssignable(spot); @@ -72,7 +107,7 @@ expectAssignable(spot); const collectionT = db.collection('test.filterQuery'); // Assert that collection.find uses the Filter helper like so: -const filter: Filter = {}; +const filter: Filter = {} as Filter; collectionT.find(filter); collectionT.find(spot); // a whole model definition is also a valid filter // Now tests below can directly test the Filter helper, and are implicitly checking collection.find @@ -96,6 +131,10 @@ expectNotType>({ name: 23 }); expectNotType>({ name: { suffix: 'Jr' } }); expectNotType>({ name: ['Spot'] }); +// it should not accept wrong types for function fields +expectNotType>({ fn: 3 }); +expectAssignable[]>(await collectionT.find({ fn: () => true }).toArray()); + /// it should query __number__ fields await collectionT.find({ age: 12 }).toArray(); /// it should not accept wrong types for number fields @@ -115,6 +154,26 @@ expectNotType>({ bestFriend: 'Andersons' }); expectNotType>({ bestFriend: [spot] }); expectNotType>({ bestFriend: [{ name: 'Andersons' }] }); +// it should permit all our BSON types as query values +expectAssignable>({ binary: new Binary('', 2) }); +expectAssignable>({ code: new Code(() => true) }); +expectAssignable>({ minKey: new MinKey() }); +expectAssignable>({ maxKey: new MaxKey() }); +expectAssignable>({ dBRef: new DBRef('collection', new ObjectId()) }); +expectAssignable>({ bSONSymbol: new BSONSymbol('hi') }); + +// None of the bson types should be broken up into their nested keys +expectNotType>({ 'binary.sub_type': 2 }); +expectNotType>({ 'code.code': 'string' }); +expectNotType>({ 'minKey._bsontype': 'MinKey' }); +expectNotType>({ 'maxKey._bsontype': 'MaxKey' }); +expectNotType>({ 'dBRef.collection': 'collection' }); +expectNotType>({ 'bSONSymbol.value': 'hi' }); +expectNotType>({ 'numOfPats.__isLong__': true }); +expectNotType>({ 'playTimePercent.bytes.BYTES_PER_ELEMENT': 1 }); +expectNotType>({ 'binary.sub_type': 'blah' }); +expectNotType>({ 'regex.dotAll': true }); + /// it should query __nested document__ fields using dot-notation collectionT.find({ 'meta.updatedAt': new Date() }); collectionT.find({ 'meta.deep.nested.level': 123 }); @@ -144,8 +203,6 @@ expectNotType>({ 'friends.0.name': 123 }); expectNotType>({ 'playmates.0.name': 123 }); expectNotType>({ 'laps.foo': 'string' }); expectNotType>({ 'treats.0': 123 }); -expectNotType>({ 'numOfPats.__isLong__': true }); -expectNotType>({ 'playTimePercent.bytes.BYTES_PER_ELEMENT': 1 }); // Nested arrays aren't checked expectNotType>({ 'meta.deep.nestedArray.0': 'not a number' });