Skip to content

Commit 5237fd4

Browse files
DOCSP-27376: removed support for dot notation in find* (#491)
Co-authored-by: Jordan Smith <[email protected]>
1 parent 456948c commit 5237fd4

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

source/fundamentals/typescript.txt

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@ You can find a code snippet that shows how to specify a type for the ``FindCurso
8484
class in the
8585
:ref:`Find Multiple Documents Usage Example <node-driver-find-usage-example-code-snippet>`.
8686

87+
.. _node-ts-type-safety:
88+
8789
Type Safety and Dot Notation
8890
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8991

90-
If you specify a query or update with **dot notation**, the {+driver-short+}
91-
provides type safety if your query or update does not
92-
:ref:`reference a nested instance of a recursive type <node-driver-recursive-types-dot-notation>`.
93-
Dot notation is a syntax you can use to navigate nested JSON objects.
92+
Starting in version 5.0, by default, the {+driver-short+} does not provide type
93+
safety for operations that search on fields expressed in **dot notation**. Dot
94+
notation is a syntax you can use to navigate nested JSON objects. When
95+
you construct a filter to pass to a query, the driver will not raise a
96+
type error even if you specify an incorrectly typed value for a field expressed
97+
in dot notation.
9498

9599
The following code snippet defines the ``ClassificationPet`` interface,
96100
which includes a ``classification`` field that enables you to specify the
@@ -104,22 +108,40 @@ genus and color of dogs and cats:
104108
classification: { genus: "Canis" | "Felis"; color: string };
105109
}
106110

107-
The following code snippet correctly raises a type error when specifying
108-
the genus of an unsupported animal in a query:
111+
The driver does not raise a type error for the following code sample,
112+
even though the value of ``classification.color`` is a boolean
113+
instead of a string:
109114

110115
.. code-block:: typescript
111116

112-
database
113-
.collection<ClassificationPet>("<your collection>")
114-
.find({ "classification.genus": "Sylvilagus" });
117+
await collection.findOneAndDelete({ "classification.color": false })
118+
119+
You can enable type-checking by constructing filters as ``StrictFilter`` or
120+
``StrictUpdateFilter`` types.
115121

116-
The type error raised by the preceding code snippet is as follows:
122+
.. warning::
123+
124+
The ``StrictFilter`` and ``StrictUpdateFilter`` types are experimental and
125+
may show type errors in valid queries where there should be none.
117126

118-
.. code-block:: none
127+
In the following code sample, the filter is assigned a
128+
``StrictFilter`` type. Given this filter type, the {+driver-short+}
129+
reports a type error because the value of ``classification.color`` is a
130+
boolean instead of a string.
131+
132+
.. code-block:: typescript
119133

120-
No overload matches this call.
121-
...
122-
Type '"Sylvilagus"' is not assignable to type 'Condition<"Canis" | "Felis">'.
134+
const filterPredicate: StrictFilter<ClassificationPet> = { "classification.color": false };
135+
await collection.findOneAndDelete(filterPredicate);
136+
137+
The following example assigns a ``StrictUpdateFilter`` type to an update
138+
filter. The {+driver-short+} reports a type error because the value of
139+
``classification.color`` is a boolean instead of a string.
140+
141+
.. code-block:: typescript
142+
143+
const updateFilter: StrictUpdateFilter<ClassificationPet> = { $set: { "classification.color": false } }
144+
await pets.updateOne({}, updateFilter);
123145

124146
Referencing Keys that Incorporate Variables
125147
```````````````````````````````````````````

source/whats-new.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,24 @@ What's New in 5.0
4141

4242
New features of the 5.0 {+driver-short+} release include:
4343

44+
- By default, the driver no longer checks types referenced in dot notation
45+
unless the ``StrictFilter`` type annotation is explicitly
46+
used. To learn more about this change, see the :ref:`Typescript fundamentals
47+
page <node-ts-type-safety>`.
48+
49+
.. note::
50+
51+
This change is for Typescript only, and does not affect queries or operations
52+
at runtime.
53+
4454
- Optional installation of ``@aws-sdk/credential-providers`` as a dependency.
4555

4656
- The driver no longer includes AWS SDK modules by default. Use the
4757
following ``npm`` command to install the SDK:
4858

4959
.. code-block:: bash
5060

51-
npm install --save @aws-sdk/credential-providers@3.186.0
61+
npm install --save "@aws-sdk/credential-providers@^3.201.0"
5262

5363
If you install the SDK, ``npm`` notifies you if the version of the SDK you
5464
installed is incompatible with the driver. Once you install the

0 commit comments

Comments
 (0)