w3resource

MongoDB Exercises: Movies collection

MongoDB Query Exercises and Solution : Movie collection - 28 Exercises

Sample document of 'movies' collection:

  {
    _id: ObjectId("573a1390f29313caabcd42e8"),
plot: 'A group of bandits stage a brazen train hold-up, only to find a determined posse hot on their heels.',
genres: [ 'Short', 'Western' ],
runtime: 11,
cast: [
      'A.C. Abadie',
      "Gilbert M. 'Broncho Billy' Anderson",
      'George Barnes',
      'Justus D. Barnes'
    ],
poster: 'https://m.media-amazon.com/images/M/MV5BMTU3NjE5NzYtYTYyNS00MDVmLWIwYjgtMmYwYWIxZDYyNzU2XkEyXkFqcGdeQXVyNzQzNzQxNzI@._V1_SY1000_SX677_AL_.jpg',
title: 'The Great Train Robbery',
fullplot: "Among the earliest existing films in American cinema - notable as the first film that presented a narrative story to tell - it depicts a group of cowboy outlaws who hold up a train and rob the passengers. They are then pursued by a Sheriff's posse. Several scenes have color included - all hand tinted.",
languages: [ 'English' ],
released: ISODate("1903-12-01T00:00:00.000Z"),
directors: [ 'Edwin S. Porter' ],
rated: 'TV-G',
awards: { wins: 1, nominations: 0, text: '1 win.' },
lastupdated: '2015-08-13 00:27:59.177000000',
year: 1903,
imdb: { rating: 7.4, votes: 9847, id: 439 },
countries: [ 'USA' ],
type: 'movie',
tomatoes: {
viewer: { rating: 3.7, numReviews: 2559, meter: 75 },
fresh: 6,
critic: { rating: 7.6, numReviews: 6, meter: 100 },
rotten: 0,
lastUpdated: ISODate("2015-08-08T19:16:10.000Z")
    }
.....

You may download the compressed file and uncompress it to find the collection used in our exercises. The collection comprises of 2000 documents.

1. Find all movies with full information from the 'movies' collection that released in the year 1893.
Click me to see the solution

2. Find all movies with full information from the 'movies' collection that have a runtime greater than 120 minutes.
Click me to see the solution

3. Find all movies with full information from the 'movies' collection that have "Short" genre.
Click me to see the solution

4. Retrieve all movies from the 'movies' collection that were directed by "William K.L. Dickson" and include complete information for each movie.
Click me to see the solution

5. Retrieve all movies from the 'movies' collection that were released in the USA and include complete information for each movie.
Click me to see the solution

6. Retrieve all movies from the 'movies' collection that have complete information and are rated as "UNRATED".
Click me to see the solution

7. Retrieve all movies from the 'movies' collection that have complete information and have received more than 1000 votes on IMDb.
Click me to see the solution

8. Retrieve all movies from the 'movies' collection that have complete information and have an IMDb rating higher than 7.
Click me to see the solution

9. Retrieve all movies from the 'movies' collection that have complete information and have a viewer rating higher than 4 on Tomatoes.
Click me to see the solution

10. Retrieve all movies from the 'movies' collection that have received an award.
Click me to see the solution

11. Find all movies with title, languages, released, directors, writers, awards, year, genres, runtime, cast, countries from the 'movies' collection in MongoDB that have at least one nomination.
Click me to see the solution

12. Find all movies with title, languages, released, directors, writers, awards, year, genres, runtime, cast, countries from the 'movies' collection in MongoDB with cast including "Charles Kayser".
Click me to see the solution

13. Retrieve all movies with title, languages, released, directors, writers, countries from the 'movies' collection in MongoDB that released on May 9, 1893.
Click me to see the solution

14. Retrieve all movies with title, languages, released, directors, writers, countries from the 'movies' collection in MongoDB that have a word "scene" in the title.
Click me to see the solution

15. Find all movies with title, languages, released, directors, viewer, writers, countries from the 'movies' collection in MongoDB that have a viewer rating of at least 3 and less than 4 on Tomatoes.
Click me to see the solution

16. Retrieve all movies with title, languages, released, year, directors, writers, countries from the 'movies' collection in MongoDB that released before the year 1900.
Click me to see the solution

17. Find all movies with title, languages, fullplot, released, directors, writers, countries from the 'movies' collection in MongoDB that have a fullplot containing the word "fire".
Click me to see the solution

18. Return all movies with title, languages, plot, released, directors, writers, and countries from the 'movies' collection in MongoDB where the word "beer" mentioned in the plot.
Click me to see the solution

19. Return all movies with title, languages, fullplot, released, directors, writers, and countries from the 'movies' collection in MongoDB where the word "metal" mentioned in the fullplot.
Click me to see the solution

20. Find all movies with title, languages, released, runtime, directors, writers, countries from the 'movies' collection in MongoDB that have a runtime between 60 and 90 minutes.
Click me to see the solution

21. Find all movies with title, languages, released, runtime, directors, writers, countries, imdb from the 'movies' collection in MongoDB for the top 5 movies with the highest IMDb ratings.
Click me to see the solution

22. Find all movies from the 'movies' collection in MongoDB with the average runtime of movies released in each country.
Click me to see the solution

23. Find from the 'movies' collection in MongoDB with the most common genre among the movies.
Click me to see the solution

24. Find the movies released in the year with the highest average IMDb rating from the 'movies' collection in MongoDB.
Click me to see the solution

25. Find the top 10 directors with the most movies from the 'movies' collection in MongoDB.
Click me to see the solution

26. Write a query in MongoDB to find the average IMDb rating for movies with different ratings (e.g., 'PG', 'R', 'G') from the 'movies' collection.
Click me to see the solution

27. Write a query in MongoDB to find the oldest movie with an award win from the 'movies' collection.
Click me to see the solution

28. Write a query in MongoDB to find the movie with the highest IMDb rating and viewer rating on Tomatoes from the 'movies' collection.
Click me to see the solution

Click here to get Sample movie Dataset from MongoDB.

More to Come !



Follow us on Facebook and Twitter for latest update.