Skip to content

Commit 2a4b6b7

Browse files
committed
JS feedback
1 parent 8cf7604 commit 2a4b6b7

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

source/integrations/mongoose-get-started.txt

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ helpful to reference when getting started with Mongoose.
102102
exists()
103103
````````
104104

105-
The ``exists()`` method returns either null or the ``ObjectId`` of a document that
105+
The ``exists()`` method returns either ``null`` or the ``ObjectId`` of a document that
106106
matches the provided query. The following is an example of matching an article
107107
based on the ``author`` field:
108108

@@ -111,12 +111,16 @@ based on the ``author`` field:
111111
const blog = await Blog.exists({ author: 'Jess Garcia' });
112112
console.log(blog);
113113

114+
For more information, see the `Model.exists()
115+
<https://mongoosejs.com/docs/api/model.html#Model.exists()>`__ section of the
116+
Mongoose API documentation.
117+
114118
where()
115119
```````
116120

117-
Mongoose has a unique style of querying data. The ``where()`` method allows you to
118-
chain and build queries. The following is an example of performing a find
119-
operation using ``findOne()`` and the equivalent approach using the ``where()`` method:
121+
The ``where()`` method allows you to chain and build queries. The following is
122+
an example of performing a find operation by using ``findOne()`` and the equivalent
123+
approach by using the ``where()`` method:
120124

121125
.. code-block:: javascript
122126

@@ -137,12 +141,16 @@ after your query, as shown in the following example:
137141
const blog = await Blog.where("author").equals("Jess Garcia").select("title author");
138142
console.log(blog);
139143

144+
For more information, see the `Model.where()
145+
<https://mongoosejs.com/docs/api/model.html#Model.$where()>`__ section of the
146+
Mongoose API documentation.
147+
140148
Prerequisites
141149
-------------
142150

143151
Before you begin this tutorial, perform the following actions:
144152

145-
- Set up a MongoDB Atlas account and configure a cluster that is M0 or higher.
153+
- Set up a MongoDB Atlas account and configure a cluster.
146154
To view instructions, see the :atlas:`Get Started with Atlas
147155
</getting-started>` guide.
148156
- Install `Node.js <https://nodejs.org/en/download>`__ {+min-node-version+} or later.
@@ -152,9 +160,9 @@ Before you begin this tutorial, perform the following actions:
152160

153161
.. step:: Set up your environment.
154162

155-
This tutorial uses npm to install dependencies and nodemon to run the code
156-
locally. Run the following commands in your terminal to initialize your
157-
project and install the necessary dependencies:
163+
This tutorial uses `nodemon <https://www.npmjs.com/package/nodemon>`__ to
164+
run the code locally. Run the following commands in your terminal to
165+
initialize your project and install the necessary dependencies:
158166

159167
.. code-block:: bash
160168

@@ -199,8 +207,9 @@ Before you begin this tutorial, perform the following actions:
199207
schema and model.
200208

201209
With Mongoose, you create a schema model file for each schema that is
202-
needed. To do this, use the folder/file structure. Create the
203-
``model/Blog.js`` folder/file. Open this file and add the following code:
210+
needed. First, create the a folder called ``model`` to put all your schema
211+
files in, then create your first schema file called ``Blog.js``. Open this
212+
file and add the following code:
204213

205214
.. literalinclude:: /includes/integrations/mongoose-blogSchema.js
206215
:language: javascript
@@ -274,7 +283,9 @@ Before you begin this tutorial, perform the following actions:
274283

275284
To update data, you can directly edit the local object with Mongoose.
276285
Then, you can use the ``save()`` method to write the update to the
277-
database. Add the following code to update the article you inserted in the
286+
database.
287+
288+
Add the following code to update the article you inserted in the
278289
previous section:
279290

280291
.. io-code-block::
@@ -413,14 +424,14 @@ Before you begin this tutorial, perform the following actions:
413424

414425
.. step:: Validate Your Data
415426

416-
The articles inserted so far have not contained the ``author``, ``dates``,
417-
or ``comments`` fields, even though these fields are included in the
418-
schema. This is because although you defined the structure of your
419-
document, you have not defined which fields are required. Without defining
420-
the required fields, you can omit any fields.
427+
The articles inserted in the previous steps do not contain the ``author``,
428+
``dates``, or ``comments`` fields, even though these fields are included
429+
in the schema. This is because although you defined the structure of your
430+
document, you have not defined which fields are required. Any field that
431+
is no defined as required can be omitted.
421432

422433
To add data validation and define these requirements, update the schema in
423-
``Blog.js`` like the following:
434+
``Blog.js`` as shown in the following example:
424435

425436
.. literalinclude:: /includes/integrations/mongoose-blogSchema-validate.js
426437
:language: javascript
@@ -437,12 +448,11 @@ Before you begin this tutorial, perform the following actions:
437448
``value: {type: String}``.
438449

439450
You can use several validation methods with Mongoose. For example, you can
440-
set ``required`` to true on any fields that you want to require.
441-
442-
You can also validate the type and the formatting. In the preceding code,
443-
the ``slug`` field is defined as a ``string`` that is always in
444-
``lowercase``. This validation takes the slug input and converts it to
445-
lowercase before saving the document to the database.
451+
set ``required`` to true on any fields that you want to require. You can
452+
also validate the type and the formatting. In the preceding code, the
453+
``slug`` field is defined as a ``string`` that is always in ``lowercase``.
454+
This validation takes the slug input and converts it to lowercase before
455+
saving the document to the database.
446456

447457
For the ``createdAt`` date field, you can set the default by using an
448458
arrow function. This field is also specified to be impossible to change
@@ -454,8 +464,8 @@ Before you begin this tutorial, perform the following actions:
454464

455465
.. step:: Introduce Multiple Schemas
456466

457-
Now that you have validation on your blog schema, and the author field is
458-
``required``, you must update ``index.js`` to include the author. To do
467+
Now that you have validation on your blog schema, and the ``author`` field is
468+
``required``, you must update ``index.js`` to include the ``author``. To do
459469
this, you can create a separate schema.
460470

461471
In the ``model`` folder, create a new file named ``User.js``. Add the
@@ -508,7 +518,7 @@ Before you begin this tutorial, perform the following actions:
508518
:start-after: start-user-import
509519
:end-before: end-user-import
510520

511-
Since you added field validation to the blog schema, the previous code to
521+
Because you added field validation to the blog schema, the previous code to
512522
insert, update, and delete blogs, and to specify fields to project, won't
513523
pass the validation and the application will error.
514524

@@ -579,13 +589,13 @@ Before you begin this tutorial, perform the following actions:
579589
__v: 0
580590
}
581591

582-
This populates the data for the ``author`` field in the data for this
583-
article. Mongoose uses the MongoDB ``$lookup`` method to do this under the
584-
hood.
592+
This populates the data for the ``author`` field with the data for this
593+
article. Mongoose uses the MongoDB ``$lookup`` method to populate the data
594+
automatically.
585595

586596
.. step:: Add Middleware
587597

588-
In Mongoose, middleware are functions that run before, and, or during the
598+
In Mongoose, middleware are functions that run before, or during, the
589599
execution of asynchronous functions at the schema level.
590600

591601
To use middleware in this project, go to the ``Blog.js`` file. Here you
@@ -635,13 +645,19 @@ Before you begin this tutorial, perform the following actions:
635645
Besides the ``pre()`` middleware function, Mongoose also offers a
636646
``post()`` middleware function.
637647

638-
Resources and Next Steps
639-
------------------------
648+
Next Steps
649+
----------
640650

641651
You now have a sample project that uses Mongoose to perform CRUD operations on a
642652
MongoDB collection. From here, you can choose to build on this project to
643653
incorporate :ref:`Mongoose helper methods
644654
<node-mongoose-get-started-helper-methods>` and build more complex queries.
645655

656+
Additional Resources
657+
--------------------
658+
646659
To learn more about using Mongoose with MongoDB, see the `Mongoose documentation
647660
<https://mongoosejs.com/docs/guide.html>`__.
661+
662+
To find support or to contribute to the MongoDB community, see the `MongoDB
663+
Developer Community <https://www.mongodb.com/community/>`__ page.

0 commit comments

Comments
 (0)