You are on page 1of 5

Mid Examination

Subject: Information Management


Study Program: Informatics
Student’s Name: Muhammad Ilham Pratama
Student ID: 001202200092

5. MongoDB movies.json
Data Querying
a. List all movies released in a specific year.
db. Movie_Collection.find({year: 2010})
b. Find all movies directed by a specific director
db. Movie_Collection _Collection.find({directors: { $regex: "William K.L. Dickson"}})

c. Find all movies that belong to a specific


db. Movie_Collection.find({genres: { $regex: "Short"}})
d. Find all movies where a specific actor/actress is part of the cast
db. Movie_Collection.find({cast: { $regex: "John Ott"}})

- Data Modification
a. Update the year of release for a specific movie
db. Movie_Collection.updateMany({year: 2010}, { $set: {"year": 2023}})
b. Add new field to store the rating of a movie
db.Movie_Collection.updateMany({}, [{ $set: { rating: "$imdb.rating" } }]);

Data Aggregation
a. Use aggregation pipeline to calculate the averaging rating for all movies
db. Movie_Collection.aggregate([{$group: {_id: null,averageRating: { $avg:
"$imdb.rating" }}}])
b. Use aggregation pipeline to group movies by genre and calculates the
average rating for each genre
db. Movie_Collection.aggregate([{$unwind: "$genres"},{$group: {_id:
"$genres",averageRating: { $avg: "$rating" }}}])

You might also like