Leaving Movie Reviews
Explore how to implement CRUD operations for movie reviews in a Node.js backend. Learn to create routes for posting, editing, and deleting reviews, use request body data, and ensure user authentication with MongoDB ObjectIds. Understand how to build and initiate ReviewsDAO to manage review data access efficiently.
In this lesson, we’ll learn how to leave reviews for movies.
MOVIEREVIEWS_DB_URI=mongodb+srv://admin:hello@cluster0.yjxj4.mongodb.net/sample_mflix?retryWrites=true&w=majority MOVIEREVIEWS_NS=sample_mflix PORT=5000
So let’s create the routes to post, put, and delete reviews. The post method is for creating a review, put is for editing a review, and delete is for deleting reviews. In the route file movies.route.js, let’s add the routes, as shown below:
Line 3: We import the ReviewsController, which we’ll create later.
Lines 6–11: We then add a /review route that handles post, put, and delete HTTP requests within this one route call. That is to say, if the /review route receives a post HTTP request to add a review, we call ...