MongoDB Assignment 1
1. Find all movies where:
i. Runtime is greater than 150 minutes:
db.movies.find({runtime:{$gt:150}}).count()
ii. Rating is higher than 8.5
db.movies.find({rating:{$gt:8.5}}).count()
iii. Year is between 2000 and 2015 (inclusive)
db.movies.find({year:{$gt:2000,$lt:2015}}).count()
iv. Box office earnings were less than 500 million OR greater than 1 billion
db.movies.find({boxOffice:{$gt:500.0,$lt:1000.0}}).count()
2. Find movies directed by Christopher Nolan that won an Oscar, made more than 700 million at box office, and are available on Netflix.:
db.movies.find({$and:[{director:"Christopher Nolan"}, {isOscarWinner:true},
{boxOffice:{$gt:700}}, {streamingOn:"Netflix"}]},{title:true,_id:false})
3. Find movies that have special features, where both behind-the-scenes content and deleted scenes are available.
db.movies.find({"specialFeatures.behindTheScenes":true, "specialFeatures.deletedScenes":true},{_id:false})
4. Find movies where either Carrie-Anne Moss or Morgan Freeman is in the cast, have language options available, and can be watched on at least 2 streaming platforms.
db.movies.find({$and:[{$or:[{cast:"Carrie-Anne Moss"},{cast:"Morgan Freeman"}]},
{languages:{$exists:true}}, {streamingOn:{$size:2}}]},{title:true,_id:false})
5. For the movie "Inception", add Chinese to its languages.
db.movies.updateOne({title:"Inception"},{$push:{languages:"Chinese"}})
6. Add Michael Caine to the cast of all Christopher Nolan movies.
db.movies.updateMany({director:"Christopher Nolan"},{$push:{cast:"Michael Caine"}})
7. Add Disney+ as a streaming option for all movies longer than 140 minutes.
db.movies.updateMany({runtime:{$gt:140}},{$push:{streamingOn:"Disney+"}})
8. Find movies that have exactly 2 genres and have box office earnings listed, but don't have any special features.
db.movies.find({genre:{$size:2}},{boxOffice:true,_id:false})
9. Remove all movies with rating less than 8.0.
db.movies.deleteMany({rating:{$lt:8.0}})
10. Remove Netflix from the streaming platforms of all movies released before 2000.
db.movies.updateMany({year:{$lt:2000}},{$pull:{streamingOn:"Netflix"}})
11. Find movies where box office earnings are more than 10 times the runtime.
db.movies.find({$expr:{$gt:["$boxOffice", {$multiply:[10, "$runtime"]}]}})
12. Find all movies available on exactly the same streaming platforms as "The Matrix".
13. Find movies that have both "Action" and "Sci-Fi" in their genres.
db.movies.find({$and:[{genre:"Action"},{genre:"Sci-Fi"}]})
14. Find movies where "Action" is the first genre listed.
db.movies.find({"genre.0": "Action"})
15. Find movies that have exactly 3 cast members.
db.movies.find({cast:{$size:3}})
© 2024 MongoDB Assignment. Designed by Hardeep Ijardar.