- Introduction
- Objectives
- Movies API Documentation
- Swagger Movie API Documentation
- Creating a Docker Image and Container
- Dependencies
- Resources
- Getting Started
This assessment measures your understanding of MongoDB and your capability to implement its features in a practical manner. You have creative freedom in the topic, material, and purpose of the web application you will be developing, so have fun with it! However, remember to plan the scope of your project to the timeline you have been given.
- Create a server application with Node, Express, and MongoDB.
- Create a CRUD API using Express and MongoDB.
- Use MongoDB indexing to make efficient queries.
- Create MongoDB validation rules.
- Use MongoDB validation to ensure data consistency.
The Movies API allows you to manage a collection of movies. It supports CRUD (Create, Read, Update, Delete) operations to interact with movie data.
-
Endpoint:
GET /
-
Description: Get a list of all movies.
-
Example Usage:
GET http://localhost:5000/movies
- Example Response:
[
{
"_id": {
"$oid": "573a1391f29313caabcd7db6"
},
"plot": "In Paris a wild girl becomes possessed by the soul of her twin who died to save her life.",
"genres": [
"Drama"
],
"runtime": 82,
"cast": [
"Betty Compson",
"Clive Brook",
"Henry Victor",
"A.B. Imeson"
],
"title": "White Shadows",
"fullplot": "In Paris a wild girl becomes possessed by the soul of her twin who died to save her life.",
"languages": [
"English"
],
"released": {
"$date": {
"$numberLong": "-1440892800000"
}
},
"directors": [
"Graham Cutts"
],
"writers": [
"Alfred Hitchcock",
"Michael Morton (novel)"
],
"awards": {
"wins": 1,
"nominations": 0,
"text": "1 win."
},
"lastupdated": "2015-05-10 00:19:38.277000000",
"year": 1924,
"imdb": {
"rating": 6.5,
"votes": 156,
"id": 15493
},
"countries": [
"UK"
],
"type": "movie",
"tomatoes": {
"viewer": {
"rating": 2.8,
"numReviews": 11
},
"lastUpdated": {
"$date": "2015-06-14T18:00:09.000Z"
}
},
"num_mflix_comments": 0
}
// ...
]
-
Endpoint:
GET /:id
-
Description: Get details of a specific movie by ID.
-
Parameters:
- id: Movie ID
-
Example Usage:
GET http://localhost:5000/movies/573a1391f29313caabcd7db6
- Example Response:
{
"_id": {
"$oid": "573a1391f29313caabcd7db6"
},
"plot": "In Paris a wild girl becomes possessed by the soul of her twin who died to save her life.",
"genres": [
"Drama"
],
"runtime": 82,
"cast": [
"Betty Compson",
"Clive Brook",
"Henry Victor",
"A.B. Imeson"
],
"title": "White Shadows",
"fullplot": "In Paris a wild girl becomes possessed by the soul of her twin who died to save her life.",
"languages": [
"English"
],
"released": {
"$date": {
"$numberLong": "-1440892800000"
}
},
"directors": [
"Graham Cutts"
],
"writers": [
"Alfred Hitchcock",
"Michael Morton (novel)"
],
"awards": {
"wins": 1,
"nominations": 0,
"text": "1 win."
},
"lastupdated": "2015-05-10 00:19:38.277000000",
"year": 1924,
"imdb": {
"rating": 6.5,
"votes": 156,
"id": 15493
},
"countries": [
"UK"
],
"type": "movie",
"tomatoes": {
"viewer": {
"rating": 2.8,
"numReviews": 11
},
"lastUpdated": {
"$date": "2015-06-14T18:00:09.000Z"
}
},
"num_mflix_comments": 0
}
-
Endpoint:
GET /
-
Description: Add a new movie to the collection.
-
Example Usage:
POST http://localhost:5000/movies
- Request Body:
{
"plot": "Takuma Sakamoto, a reclusive gamer, is unexpectedly transported into the virtual world of his favorite MMORPG as his in-game character, the powerful Demon Lord Diablo. Two girls who summoned him to control him end up becoming his servants due to a magic rebound. Takuma, dealing with social anxiety, adopts his in-game persona to navigate the new world. Alongside his companions, Rem and Shera, he embarks on a quest to remove the magic collars while assisting them with their personal struggles that led to their summoning.",
"genres": ["isekai"],
"runtime":23,
"cast": [
"Diablo",
"Sheera",
"Rem"
],
"poster": "https://thecinemaholic.com/wp-content/uploads/2021/06/How-not-to-summon.jpg",
"title": "How not to summon a Demon Lord season 2",
"fullplot": "Takuma Sakamoto, a reclusive gamer, is unexpectedly transported into the virtual world of his favorite MMORPG as his in-game character, the powerful Demon Lord Diablo. Two girls who summoned him to control him end up becoming his servants due to a magic rebound. Takuma, dealing with social anxiety, adopts his in-game persona to navigate the new world. Alongside his companions, Rem and Shera, he embarks on a quest to remove the magic collars while assisting them with their personal struggles that led to their summoning.",
"languages": [
"English"
],
"released": "2021-04-09T00:00:00.000Z",
"directors": [
"Satoshi Kuwabara"
],
"rated": "TV-G",
"awards": {},
"lastupdated": "",
"year": 2018,
"imdb": {},
"countries": [
"JAPAN"
],
"type": "ANIME",
"tomatoes": {
"viewer": {},
"fresh": 6,
"critic": {
"rating": 7.6,
"numReviews": 6,
"meter": 100
},
"rotten": 0,
"lastUpdated": ""
},
"num_mflix_comments": 0
}
- Example Response:
{
"acknowledged": true,
"insertedId": "6557d63b84def3c71fe4da1c"
}
- Endpoint: PUT /:id
- Description: Update details of a specific movie by ID.
- Parameters:
id
: Movie ID
- Request Body:
{
"type": "ANIMES WEB SERIES"
}
- Example Usage:
PUT http://localhost:5000/movies/573a1391f29313caabcd7db6
- Example Response:
{
"acknowledged": true,
"modifiedCount": 1,
"upsertedId": null,
"upsertedCount": 0,
"matchedCount": 1
}
-
Endpoint:
DELETE /:id
-
Description: Delete a specific movie by ID.
-
Parameters:
id
: Movie ID
-
Example Usage:
DELETE http://localhost:5000/movies/573a1391f29313caabcd7db6
- Example Response:
{
"acknowledged": true,
"deletedCount": 1
}
- Validation Rules Function:
// Define validation rules for the movies collection
const validationRules = {
$jsonSchema: {
bsonType: "object",
required: ["plot", "genres", "type", "title", "poster", "cast", "fullplot", "runtime"],
// ...
}
};
- Validation Example REQUEST
- Validation Example Response
- If the request fails, the API will respond with an appropriate error message and status code.
The below screenshot is the API documentation for the routers in the project.
The url to the swaggerUI API documentation is: swaggerUI API Documentation
get_all_movies.mp4
get_a_single_movie.mp4
post_a_movies.mp4
update_a_movie.mp4
delete_a_movie.mp4
Docker is is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly.
- Install docker desktop application: To create a docker container & image, download & install docker desktop: Install Docker Desktop
- Create a Dockerfile in the root directory of the project.
- Create a
.dockerignore
to exclude modules. Sample .dockerignore. - Create a docker compose to define the service(s) that will be used for the project. Docker Compose is is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services. Then, with a single command, you create and start all the services from your configuration.
Here is a sample Docker Compose.
- Lastly, build the docker container with the command:
docker-compose up -d --build
The Express application will be running on http://localhost:5000/api/movies.
- Docker Repository: The docker image can be downloaded on hub.docker.com. Use the command to pull the docker image:
docker pull sam12302021/sba_319_mongodb-api
- chai
- chai-http
- dotenv
- express
- mocha
- mongodb
- nodemon
- swagger-jsdoc
- swagger-ui-express
- yamljs
- Mocha and Chai for testing.
- Swagger for Movie API Documentation.
- Test a Node RESTful API with Mocha and Chai
- Documenting your Express API with Swagger
- Docker to build docker images.
- Docker Compose for defining and running multi-container Docker applications.
Clone this repo: sba_319_MongoDB_Database_Application.
- Install dependencies:
npm install
or
npm i
- Start local server:
npm run start