Share
Explore

Lab Test 2 Version C W23 Mad 6123

Building the Back End Data Store for the Node.js Full Stack Web Application: Lab Test


Scenario:
You are building a Node.js full stack web application for a movie theater that allows customers to purchase tickets online. You need to create a back end data store using MongoDB to store information about movie theaters, movie showtimes, and ticket sales.


Sample Data:


Theater 1: AMC Theatres
Theater 2: Regal Cinemas
Movie 1: The Dark Knight
Movie 2: Titanic
Movie 3: Avatar
Showtime 1: 2022-05-01 18:00:00
Showtime 2: 2022-05-01 20:00:00
Showtime 3: 2022-05-01 22:00:00
Purchaser 1: John Doe
Purchaser 2: Jane Smith
Purchaser 3: Bob Johnson


Instructions:


Create a MongoDB database called "movie_tickets".
Create a collection called "theaters" with the following fields:


name (string)
address (string)


Insert the sample data for the two theaters.
Create a collection called "movies" with the following fields:


title (string)
description (string)
duration (integer)
rating (string)
genre (string)


Insert the sample data for the three movies.
Create a collection called "showtimes" with the following fields:


theater_id (ObjectID)
movie_id (ObjectID)
start_time (Date)
end_time (Date)
price (float)


Insert the sample data for the three showtimes for each theater and movie.
Create a collection called "purchasers" with the following fields:


name (string)
email (string)


Insert the sample data for the three purchasers.
Create a collection called "tickets" with the following fields:
purchaser_id (ObjectID)
showtime_id (ObjectID)
seat_number (string)
Insert some sample data for ticket sales for each showtime and purchaser.
Use the $lookup operator to join the collections and retrieve a list of tickets purchased by each purchaser and a list of showtimes for each theater.


Sample Code:


db.purchasers.aggregate([
{ $lookup:
{
from: "tickets",
localField: "_id",
foreignField: "purchaser_id",
as: "tickets"
}
}
])

db.theaters.aggregate([
{ $lookup:
{
from: "showtimes",
localField: "_id",
foreignField: "theater_id",
as: "showtimes"
}
}
])



Conclusion:
In this lab, we have learned how to build the back end data store for a Node.js full stack web application using MongoDB for a movie theater ticket purchasing system. We have implemented a join between collections to retrieve a list of tickets purchased by each purchaser and a list of showtimes for each theater. We have also provided sample data for theaters, movies, showtimes, purchasers, and ticket sales, and instructions on how to make a MongoDB database and implement this join using the $lookup operator.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.