Search⌘ K
AI Features

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
The initial files we will build on

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:

Javascript (babel-node)
import express from 'express'
import MoviesController from './movies.controller.js'
import ReviewsController from './reviews.controller.js'
const router = express.Router()
router.route('/').get((req,res) => res.send(MoviesController.apiGetMovies))
router
.route("/review")
.post(ReviewsController.apiPostReview)
.put(ReviewsController.apiUpdateReview)
.delete(ReviewsController.apiDeleteReview)
export default router

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 ...