@@ -15,7 +15,7 @@ Get Started with Mongoose
1515.. contents:: On this page
1616 :local:
1717 :backlinks: none
18- :depth: 1
18+ :depth: 2
1919 :class: singlecol
2020
2121Overview
@@ -39,7 +39,7 @@ In this tutorial, you will perform the following actions:
3939- Use multiple schemas and middleware
4040
4141Schemas
42- -------
42+ ~~~~~~~
4343
4444A schema defines the structure of your collection documents. A Mongoose schema
4545maps directly to a MongoDB collection.
@@ -67,7 +67,7 @@ following types are permitted:
6767- Map
6868
6969Models
70- ------
70+ ~~~~~~
7171
7272Models take your schema and apply it to each document in its collection. Models
7373are responsible for all document interactions such as create, read, update, and
@@ -158,11 +158,15 @@ folder/file. Open this file and add the following code:
158158 :language: javascript
159159 :dedent:
160160
161+ Perform CRUD Operations
162+ -----------------------
163+
161164You now have your first model and schema set up, and you can start inserting
162- data into the database.
165+ data into the database. The following sections show you how to perform CRUD
166+ operations using Mongoose.
163167
164168Insert Data
165- -----------
169+ ~~~~~~~~~~~
166170
167171Go to ``index.js`` and add the following import statement to the top of your file:
168172
@@ -216,7 +220,7 @@ To run the code, use the following command in your terminal:
216220 insert multiple articles into your database.
217221
218222Update Data
219- -----------
223+ ~~~~~~~~~~~
220224
221225To update data, you can directly edit the local object with Mongoose. Then, you
222226can use the ``save()`` method to write the update to the database. Add the
@@ -246,7 +250,7 @@ following code to update the article you inserted in the previous section:
246250 }
247251
248252Find Data
249- ---------
253+ ~~~~~~~~~
250254
251255To update a specific document, you can use the Mongoose ``findById()`` method to get
252256a document by its ``ObjectId``.
@@ -285,7 +289,7 @@ value for the document that you inserted previously:
285289 see the `Promises guide <https://mongoosejs.com/docs/promises.html>`__ in the Mongoose documentation.
286290
287291Specify Document Fields
288- -----------------------
292+ ~~~~~~~~~~~~~~~~~~~~~~~
289293
290294Like with the {+driver-short+}, you can use Mongoose to project only the fields that
291295you need. The following code specifies to only project the ``title``, ``slug``, and
@@ -315,7 +319,7 @@ previously:
315319 }
316320
317321Delete Data
318- -----------
322+ ~~~~~~~~~~~
319323
320324Mongoose uses the ``deleteOne()`` and ``deleteMany()`` methods to delete data from a
321325collection. You can specify the field of the document you want to delete and
@@ -621,7 +625,7 @@ update the title, and then save the updated article:
621625 updated: 2025-05-15T18:18:30.249Z
622626 }
623627
624- When this runs , the returned article includes an ``updated`` date.
628+ When you run the application , the returned article includes an ``updated`` date.
625629
626630Besides the ``pre()`` middleware function, Mongoose also offers a ``post()``
627631middleware function.
0 commit comments