@@ -176,7 +176,7 @@ In this tutorial, you will perform the following actions:
176
176
:language: javascript
177
177
:dedent:
178
178
179
- This schema enables a ``timestamps`` option, which adds Mongoose -manged
179
+ This schema enables a ``timestamps`` option, which adds mongoose -manged
180
180
``createdAt`` and ``updatedAt`` fields to the schema that are updated
181
181
automatically. For more information, see the `Timestamps
182
182
<https://mongoosejs.com/docs/timestamps.html>`__ page in the Mongoose
@@ -685,9 +685,14 @@ query with the ``where()`` method:
685
685
const blogFind = await Blog.findOne({ author: "Jess Garcia" });
686
686
console.log(blogFind);
687
687
688
- const blogWhere = await Blog.where("author").equals("Jess Garcia");
688
+ const blogWhere = await Blog.findOne(). where("author").equals("Jess Garcia");
689
689
console.log(blogWhere);
690
690
691
+ In this implementation, the ``where()`` implementation starts with a
692
+ ``findOne()`` which tells Mongoose to treat it as a ``findOne()`` query. This is
693
+ important because if you use ``where()`` on its own (``Blog.where(...)``),
694
+ Mongoose implicitly treats it as a ``find()`` operation.
695
+
691
696
Generally, the ``where()`` method is used for complex queries involving dynamic
692
697
query building or multiple comparators, or when using this method improves
693
698
readability. There is no performance difference between using the
@@ -698,7 +703,7 @@ after your query, as shown in the following example:
698
703
699
704
.. code-block:: javascript
700
705
701
- const blog = await Blog.where("author").equals("Jess Garcia").select("title author");
706
+ const blog = await Blog.findOne(). where("author").equals("Jess Garcia").select("title author");
702
707
console.log(blog);
703
708
704
709
For more information, see the following sections of the Mongoose API
0 commit comments