@@ -266,19 +266,28 @@ Find Methods and the _id Field
266
266
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267
267
268
268
The ``find`` and ``findOne`` methods of the ``Collection`` class include
269
- the ``_id`` field in their return type.
269
+ the ``_id`` field in their return type. The driver infers the type of the
270
+ returned ``_id`` field based on the type parameter you passed to your
271
+ ``Collection`` instance.
270
272
271
273
If the type parameter you passed to your ``Collection`` instance includes the
272
- ``_id`` field, the type of the ``_id`` field in the values returned from the
273
- find methods is the same as the type of the ``_id``
274
- field in your type parameter.
274
+ ``_id`` field in its schema, the driver infers that the ``_id`` field returned
275
+ from the method is of the type specified in the schema.
275
276
276
- If the type parameter you passed to your ``Collection`` instance does not include the ``_id``
277
- field, the driver gives the ``_id`` field in the values returned from the find methods
278
- the type ``ObjectId``.
277
+ However, if the type parameter you passed to your ``Collection`` instance does not
278
+ include the ``_id`` field in its schema, the driver infers that the type of the
279
+ ``_id`` field returned from the method is ``ObjectId``.
279
280
280
- The following code uses the :ref:`Pet <mongodb-node-typescript-pet-interface>` interface to return
281
- a document with an ``_id`` of type ``ObjectId``:
281
+ .. tip::
282
+
283
+ The type parameter passed to your ``Collection`` influences only the type
284
+ inference of the fields returned from the method. The driver does not convert
285
+ the field to the specified type. The type of each field in your type
286
+ parameter's schema should match the type of the corresponding field in the
287
+ collection.
288
+
289
+ The following code uses the :ref:`Pet <mongodb-node-typescript-pet-interface>`
290
+ interface to return a document with an ``_id`` inferred to be of type ``ObjectId``:
282
291
283
292
.. code-block:: typescript
284
293
@@ -291,7 +300,7 @@ a document with an ``_id`` of type ``ObjectId``:
291
300
const id : ObjectId = document._id;
292
301
293
302
The following code uses the ``IdNumberPet`` interface to return a
294
- document with an ``_id`` field of type ``number``:
303
+ document with an ``_id`` inferred to be of type ``number``:
295
304
296
305
.. code-block:: typescript
297
306
0 commit comments