@@ -288,19 +288,28 @@ Find Methods and the _id Field
288
288
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
289
289
290
290
The ``find`` and ``findOne`` methods of the ``Collection`` class include
291
- the ``_id`` field in their return type.
291
+ the ``_id`` field in their return type. The driver infers the type of the
292
+ returned ``_id`` field based on the type parameter you passed to your
293
+ ``Collection`` instance.
292
294
293
295
If the type parameter you passed to your ``Collection`` instance includes the
294
- ``_id`` field, the type of the ``_id`` field in the values returned from the
295
- find methods is the same as the type of the ``_id``
296
- field in your type parameter.
296
+ ``_id`` field in its schema, the driver infers that the ``_id`` field returned
297
+ from the method is of the type specified in the schema.
297
298
298
- If the type parameter you passed to your ``Collection`` instance does not include the ``_id``
299
- field, the driver gives the ``_id`` field in the values returned from the find methods
300
- the type ``ObjectId``.
299
+ However, if the type parameter you passed to your ``Collection`` instance does not
300
+ include the ``_id`` field in its schema, the driver infers that the type of the
301
+ ``_id`` field returned from the method is ``ObjectId``.
301
302
302
- The following code uses the :ref:`Pet <mongodb-node-typescript-pet-interface>` interface to return
303
- a document with an ``_id`` of type ``ObjectId``:
303
+ .. tip::
304
+
305
+ The type parameter passed to your ``Collection`` influences only the type
306
+ inference of the fields returned from the method. The driver does not convert
307
+ the field to the specified type. The type of each field in your type
308
+ parameter's schema should match the type of the corresponding field in the
309
+ collection.
310
+
311
+ The following code uses the :ref:`Pet <mongodb-node-typescript-pet-interface>`
312
+ interface to return a document with an ``_id`` inferred to be of type ``ObjectId``:
304
313
305
314
.. code-block:: typescript
306
315
@@ -313,7 +322,7 @@ a document with an ``_id`` of type ``ObjectId``:
313
322
const id : ObjectId = document._id;
314
323
315
324
The following code uses the ``IdNumberPet`` interface to return a
316
- document with an ``_id`` field of type ``number``:
325
+ document with an ``_id`` inferred to be of type ``number``:
317
326
318
327
.. code-block:: typescript
319
328
0 commit comments