From the course: Next.js: Creating and Hosting a Full-Stack Site
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Rewriting the load product endpoint - React.js Tutorial
From the course: Next.js: Creating and Hosting a Full-Stack Site
Rewriting the load product endpoint
- [Instructor] Alright, so now that we've rewritten the list products endpoint to use MongoDB, the next endpoint that we're going to do is the endpoint for loading an individual product by its ID. So here, we have the endpoint for that, and what we're going to need to do here is replace our JavaScript logic that filtered through a JavaScript array for the correct product. We're just going to need to change this to a database query. So let's take a look at how to do this. First of all, we're going to need to import that connect to database function that we created, so let's just add that up here. We'll say import, connectToDb, and we'll just let that do the importing for us. And now that we have that, at the top of our route handler, what we're going to do is we're going to say, const db = connectToDb. And again, that is asynchronous, so we're going to need to add the await keyword before that. And now that we have that, the next thing that we're going to do is, as I said, replace this…
Contents
-
-
-
-
-
(Locked)
What is MongoDB?1m 42s
-
(Locked)
Setting up hosting for MongoDB4m 54s
-
(Locked)
Adding MongoDB to Next.js6m 46s
-
(Locked)
Adding data to MongoDB7m 32s
-
(Locked)
Rewriting the list endpoints7m 29s
-
(Locked)
Rewriting the load product endpoint4m 2s
-
(Locked)
Rewriting the shopping cart endpoint5m 27s
-
(Locked)
Rewriting the add-to-cart endpoint5m 8s
-
(Locked)
Challenge: Rewriting the remove-from-cart endpoint57s
-
(Locked)
Solution: Rewriting the remove-from-cart endpoint4m 2s
-
(Locked)
-
-
-