Professional Documents
Culture Documents
Mid Examination2
Mid Examination2
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"}})
- 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" }}}])