-
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!
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
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
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 had a few small comments and recommendations
exists() | ||
~~~~~~~~ | ||
|
||
The ``exists()`` method returns either ``null`` or the ``ObjectId`` of a document that |
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.
Not strictly true, exists()
returns either null
or the first document that matches filter with the projection { _id: 1 }
applied. So doesn't return an ObjectId, rather a POJO with an _id
property.
Also, I may be wrong but it seems a bit strange to introduce exists()
before find()
. exists()
is helpful primarily for performance reasons, most basic applications don't need to use it.
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.
Updated the exists()
description and moved the whole Helper Methods section down to the Next Steps section.
const blogFind = await Blog.findOne({ author: "Jess Garcia" }); | ||
console.log(blogFind); | ||
|
||
const blogWhere = await Blog.where("author").equals("Jess Garcia"); |
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.
It is slightly more idiomatic (but equivalent) to do Blog.find().where('author').equals('Jess Garcia')
.
However, similar to exists()
, I recommend not introducing where()
so early, and you may want to exclude it entirely. Mongoose's chaining syntax has waned in popularity in recent years.
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.
Updated the description to include general use cases.
|
||
.. note:: | ||
|
||
The Mongoose ``exec()`` function is an option of the ``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.
exec
isn't an option. I think this section should clarify that findById()
returns a Mongoose query object, and exec()
executes the query and returns a promise.
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.
Clarified.
set ``required`` to true on any fields that you want to require. You can | ||
also validate the type and the formatting. In the preceding code, the | ||
``slug`` field is defined as a ``string`` that is always in ``lowercase``. | ||
This validation takes the slug input and converts it to lowercase before |
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.
lowercase
is implemented as a setter, not a validator. However, you also added a minLength
property, which is a validator. You can update this paragraph to use minLength
instead.
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.
Used minLength
and added a custom setters section to the Next Steps section below.
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