-
Notifications
You must be signed in to change notification settings - Fork 52
DOCSP-48893 Add get started with Mongoose tutorial #1138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
DOCSP-48893 Add get started with Mongoose tutorial #1138
Conversation
✅ Deploy Preview for docs-node ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work overall! I think this page could benefit by being converted into a stepped tutorial page (as mentioned in a few of my comments). Right now it reads like a reference page but has a lot of callbacks to previous sections and relies on running through each section in order. This could be confusing to anyone treating this like a regular reference-style page. Happy to discuss more about this and brainstorm ways to go about it!
Mongoose enforces a semi-regid schema from the beginning. When you use Mongoose, | ||
you must define a schema and model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: Simplify
Mongoose enforces a semi-regid schema from the beginning. When you use Mongoose, | |
you must define a schema and model. | |
However, Mongoose enforces a semi-regid schema from the beginning, so | |
you must define a schema and model. |
|
||
Before you begin this tutorial, perform the following actions: | ||
|
||
- Set up a MongoDB Atlas account and configure a cluster that is M0 or higher. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I don't think there is a tier lower than M0? So you could configure any kind of cluster in this case
Set Up Your Environment | ||
----------------------- | ||
|
||
This tutorial uses npm to install dependencies and nodemon to run the code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Monospace (or alternatively make these links to the download pages) - also, should npm be added to the prerequisites since it's required for the tutorial?
This tutorial uses npm to install dependencies and nodemon to run the code | |
This tutorial uses ``npm`` to install dependencies and ``nodemon`` to run the code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm
is installed when you install Node.js, so I'm taking that out. I'll add the link and keep the instructions for nodemon
.
With Mongoose, you create a schema model file for each schema that is needed. To | ||
do this, use the folder/file structure. Create the ``model/Blog.js`` | ||
folder/file. Open this file and add the following code: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that everyone would easily understand what the folder/file structure is. I think it would be more clear just to tell users to create a folder called model
and then a file called Blog.js
inside it
Prerequisites | ||
------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might make sense to convert this into a stepped tutorial, from this section down to the end of the "Perform CRUD Operations" section, since these steps all need to be done in order. I could also see the stepped part starting right after this section. What do you think? Happy to discuss more about it if needed too
Now that you have validation on your blog schema, and the author field is | ||
``required``, you must update ``index.js`` to include the author. To do this, | ||
you can create a separate schema. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my earlier comment - this intro paragraph doesn't make as much sense when not in the context of a stepped tutorial. For this one I think it makes sense not to be in a tutorial though, so maybe just a rewording to make it more of a general intro paragraph would be helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
steps have been added
:start-after: start-user-import | ||
:end-before: end-user-import | ||
|
||
Since you added field validation to the blog schema, the previous code to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you added field validation to the blog schema, the previous code to | |
Because you added field validation to the blog schema, the previous code to |
This populates the data for the ``author`` field in the data for this article. | ||
Mongoose uses the MongoDB ``$lookup`` method to do this under the hood. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This populates the data for the ``author`` field in the data for this article. | |
Mongoose uses the MongoDB ``$lookup`` method to do this under the hood. | |
This populates the data for the ``author`` field with the data for this article. | |
Mongoose uses the MongoDB ``$lookup`` method to populate the data automatically. |
Middleware | ||
---------- | ||
|
||
In Mongoose, middleware are functions that run before, and, or during the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Mongoose, middleware are functions that run before, and, or during the | |
In Mongoose, middleware are functions that run before or during the |
Resources and Next Steps | ||
------------------------ | ||
|
||
You now have a sample project that uses Mongoose to perform CRUD operations on a | ||
MongoDB collection. From here, you can choose to build on this project to | ||
incorporate :ref:`Mongoose helper methods | ||
<node-mongoose-get-started-helper-methods>` and build more complex queries. | ||
|
||
To learn more about using Mongoose with MongoDB, see the `Mongoose documentation | ||
<https://mongoosejs.com/docs/guide.html>`__. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not converting this into a stepped tutorial, I would suggest converting this to an "Additional Information" section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few more fixes
schema and model. | ||
|
||
With Mongoose, you create a schema model file for each schema that is | ||
needed. First, create the a folder called ``model`` to put all your schema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed. First, create the a folder called ``model`` to put all your schema | |
needed. First, create a folder called ``model`` to put all your schema |
Insert Data | ||
~~~~~~~~~~~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section down through the Delete Data section needs be indented further to be under the procedure directive - currently it isn't rendering on the page
Find Data | ||
~~~~~~~~~ | ||
|
||
To update a specific document, you can use the Mongoose ``findById()`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be "find" not "update"
To update a specific document, you can use the Mongoose ``findById()`` | |
To find a specific document, you can use the Mongoose ``findById()`` |
Specify Document Fields | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Like with the {+driver-short+}, you can use Mongoose to project only the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like with the {+driver-short+}, you can use Mongoose to project only the | |
You can use Mongoose to project only the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM w/ a couple minor fixes
exists() | ||
~~~~~~`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exists() | |
~~~~~~`` | |
exists() | |
~~~~~~~~ |
Mongoose API documentation. | ||
|
||
where() | ||
~~~~~~` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~~~~~~` | |
~~~~~~~ |
You can also reuse the name User model for the ``comment.user`` field by | ||
changing the ``blogSchema`` definition: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should either be User
model, or the "name User
" here?
You can also reuse the name User model for the ``comment.user`` field by | |
changing the ``blogSchema`` definition: | |
You can also reuse the name ``User`` model for the ``comment.user`` field by | |
changing the ``blogSchema`` definition: |
or
You can also reuse the name User model for the ``comment.user`` field by | |
changing the ``blogSchema`` definition: | |
You can also reuse the ``User`` model for the ``comment.user`` field by | |
changing the ``blogSchema`` definition: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same User
model 🙃
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-48893
Original page - https://www.mongodb.com/developer/languages/javascript/getting-started-with-mongodb-and-mongoose/
Staging Links
Self-Review Checklist