File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -33,14 +33,17 @@ accepts a :doc:`query </fundamentals/crud/query-document>` parameter.
3333settings that affect the method's execution. Refer to the reference
3434documentation for each method for more information.
3535
36- .. important ::
36+ .. tip ::
3737
38- If you require an exact document count in your collection, use a query
39- to take advantage of the built-in index on the ``_id`` field.
38+ You can improve performance when using ``countDocuments()`` to return the
39+ total number of documents in a collection by avoiding a collection scan. To
40+ do this, use a :manual:`hint </reference/method/cursor.hint>` to take
41+ advantage of the built-in index on the ``_id`` field. Use this technique only
42+ when calling ``countDocuments()`` with an empty query parameter.
4043
41- .. code-block:: js
44+ .. code-block:: javascript
4245
43- myColl .countDocuments({ "_id": { "$exists": true } });
46+ collection .countDocuments({}, { hint: "_id_" });
4447
4548Example
4649-------
You can’t perform that action at this time.
0 commit comments