Skip to content

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

stephmarie17
Copy link
Collaborator

@stephmarie17 stephmarie17 commented May 15, 2025

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

  • integrations
  • integrations/mongoose-get-started
  • index
  • Self-Review Checklist

    • Is this free of any warnings or errors in the RST?
    • Did you run a spell-check?
    • Did you run a grammar-check?
    • Are all the links working?
    • Are the facets and meta keywords accurate?
    • Are the page titles greater than 20 characters long and SEO relevant?

    Copy link

    netlify bot commented May 15, 2025

    Deploy Preview for docs-node ready!

    Name Link
    🔨 Latest commit f7c3c23
    🔍 Latest deploy log https://app.netlify.com/projects/docs-node/deploys/6841c2669b878a000877171c
    😎 Deploy Preview https://deploy-preview-1138--docs-node.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify project configuration.

    @stephmarie17 stephmarie17 marked this pull request as ready for review May 15, 2025 22:43
    Copy link
    Collaborator

    @jordan-smith721 jordan-smith721 left a 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!

    Comment on lines 28 to 29
    Mongoose enforces a semi-regid schema from the beginning. When you use Mongoose,
    you must define a schema and model.
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    S: Simplify

    Suggested change
    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.
    Copy link
    Collaborator

    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
    Copy link
    Collaborator

    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?

    Suggested change
    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

    Copy link
    Collaborator

    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.

    Comment on lines 153 to 155
    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:
    Copy link
    Collaborator

    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

    Comment on lines 92 to 93
    Prerequisites
    -------------
    Copy link
    Collaborator

    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

    Comment on lines 455 to 457
    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.
    Copy link
    Collaborator

    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

    Copy link
    Collaborator

    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
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Suggested change
    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

    Comment on lines 578 to 579
    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.
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Suggested change
    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
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Suggested change
    In Mongoose, middleware are functions that run before, and, or during the
    In Mongoose, middleware are functions that run before or during the

    Comment on lines 633 to 642
    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>`__.
    Copy link
    Collaborator

    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

    Copy link
    Collaborator

    @jordan-smith721 jordan-smith721 left a 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
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Suggested change
    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

    Comment on lines +230 to +231
    Insert Data
    ~~~~~~~~~~~
    Copy link
    Collaborator

    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()``
    Copy link
    Collaborator

    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"

    Suggested change
    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
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Suggested change
    Like with the {+driver-short+}, you can use Mongoose to project only the
    You can use Mongoose to project only the

    Copy link
    Collaborator

    @jordan-smith721 jordan-smith721 left a 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

    Comment on lines 93 to 94
    exists()
    ~~~~~~``
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Suggested change
    exists()
    ~~~~~~``
    exists()
    ~~~~~~~~

    Mongoose API documentation.

    where()
    ~~~~~~`
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Suggested change
    ~~~~~~`
    ~~~~~~~

    Comment on lines 514 to 515
    You can also reuse the name User model for the ``comment.user`` field by
    changing the ``blogSchema`` definition:
    Copy link
    Collaborator

    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?

    Suggested change
    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

    Suggested change
    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:

    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    same User model 🙃

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants