Every data management system has at least three basic functions: create, delete, and update. In this video, learn how to create CRUD functions with Mongoose.
- [Instructor] First of all we will require the model…const ItemModel equals require…and from models I take the mongoose ItemModel…that we defined before.…Next, I will simply define an asynchronous function,…async function getAll…and that's quite easy actually…because this function does nothing more…than returning ItemModel.find all,…so we pass in an empty query object…and I want to sort it,…so I add .sort…and in round brackets I add a child script object…that says createdAt: -1.…
This will sort the result in descending order…by creation date.…Here we also have to fix a little bit the indentations…so that eslint is happy.…Next we will implement a function getOne,…so I add async function getOne…and I pass in the itemId…and return ItemModel.findOne,…that's the function provided by Mongoose…and I want to search for or query for _id,…that's the ID of this one record of the document…should be itemId.…
Let's fix here a little bit the blank…so that eslint is happy.…So, we have implemented now getAll and getOne…but we haven't yet really exported anything…
- Basics of relational and nonrelational databases
- Preparing your environment
- When to use document databases
- Inserting data into MongoDB
- Basic insert operations for MongoDB
- Querying data from MongoDB with Node.js
- Using key-value stores
- Using relational databases with Node.js
- Adding MySQL and Sequelize to a project
Skill Level Intermediate
Node.js: Extend and Maintain Applicationswith Daniel Khan3h 35m Intermediate
Node.js: Build Your First Microservicewith Daniel Khan2h 9m Intermediate
Building a Website with Node.js and Express.jswith Ray Villalobos3h 16m Intermediate
1. Get Started with Databases for Node.js
2. Prepare Your Environment
3. Use Document Databases with Node.js
4. Use Key-Value Stores with Node.js
5. Use Relational Databases with Node.js
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.