- Create a new project directory named
CineWow
- Navigate inside the project directory
- Create an
index.js
file for server entrypoint
- Initialize npm inside the project directory
- Install the external modules
express
,dotenv
,mongoose
- Create an environment file at the root of the project directory and store the environment variable
DATABASE_URL = "mongodb://localhost:27017/CineWow"
- Now, create a
db.js
file at the root of the project directory. Import the environment variable and define a functionconnectDB
that connects the ExpressJS application to MongoDB using mongoose ODM
- Import the
db.js
inside theindex.js
file and call theconnectDB
function to initialize a connection
Now, define the following routes with appropriate handler functions:
- "/api/v1/getMovies" which recieves GET request and returns the list of all movies
- "/api/v1/getMovie/:movieID" which recieves GET request and returns the movie matched with the particular movieID provided as router parameter
- "/api/v1/addMovie", which recieves POST request with valid movie data in JSON format and inserts it into the database after validation
- "/api/v1/updateMovie/:movieID", which recieves PATCH request with the fields to update JSON format, movieID as a route parameter and inserts it into the database after validation
- "/api/v1/deleteMovie:movieID", which recieves DELETE request with the movieID as a route parameter and inserts it into the database after validation
- Modify the "/api/v1/getMovies" defined in Q1, to enable filtering using query parameters such as rating, title, directors, etc
- Modify the "/api/v1/getMovies" defined in Q6, to enable filtering using only selective query parameters : [director,rating,releaseYear,title]
- Modify the "/api/v1/getMovies" defined in Q7, to allow advance filtering using the specified query paramaters: [director,rating,releaseYear,title] such that $gte, $gt, $lte, $lt operators can be invoked
- Modify the "/api/v1/getMovies" defined in Q8, to allow sorting of the movie list by one or more fields specified by the
sort
query parameter
- Modify the "/api/v1/getMovies" defined in Q9, to allow projection in the movie list by the
fields
query parameter. If thefields
query parameter is not specified, exclude the "createdAt" field.
- Modify the "/api/v1/getMovies" defined in Q10, to allow pagination specified by the
page
andlimit
query parameters.
- Define a route "/api/v1/movieStats", where an aggregation pipeline is defined with a
$match
stage to display all movies where the rating is greater or equal to 8.2
- Now, modify the "/api/v1/movieStats" in Q12, where an additional
$group
stage is used to compute and display thetotalMovies
,minYear
,maxYear
,averageRating
- Now, modify the "/api/v1/movieStats" in Q12, where an additional
$sort
stage is used to display the movies in descending order ofaverageRating
field
Bonus: Test the functionalities of each of the routes using the Postman/Thunderclient tool
Attach Screenshots for the same
NOTE: You may use this dataset for testing your CRUD Operations