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…
Author
Released
12/12/2017- 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
Duration
Views
Related Courses
-
Node.js: Testing and Code Quality
with Jon Peck3h 25m Intermediate
-
Introduction
-
Welcome38s
-
Using the exercise files1m 6s
-
-
1. Get Started with Databases for Node.js
-
2. Prepare Your Environment
-
Install Node.js1m 26s
-
Install Docker1m 44s
-
Set up the sample apps9m 3s
-
-
3. Use Document Databases with Node.js
-
Set up MongoDB4m 35s
-
Connect to MongoDB3m 26s
-
Insert data into MongoDB7m 29s
-
Query data from MongoDB4m 15s
-
Introduction to Mongoose2m 59s
-
Define your first model6m 55s
-
Implement all database functions10m 17s
-
4. Use Key-Value Stores with Node.js
-
Set up Redis2m 41s
-
Use Node.js with Redis7m 55s
-
Implement a basket service10m 20s
-
Put everything together9m 28s
-
Wire up a basket page4m 16s
-
5. Use Relational Databases with Node.js
-
Set up MySQL3m 45s
-
Create a database schema4m 7s
-
Use Node.js with MySQL10m 55s
-
Introduction to Sequelize2m 24s
-
Review the database design1m 23s
-
Implement an order service8m 30s
-
Conclusion
-
Next steps37s
-
- 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.
CancelTake 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.
Share this video
Embed this video
Video: Implement all database functions