w3resource

Find movies with runtime greater than 120 minutes


Find all movies with full information from the 'movies' collection that have a runtime greater than 120 minutes.

Structure 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")
    }
.....

Query:

db.movies.find({ "runtime": { $gt: 120 } })

Output:

  {
    _id: ObjectId("573a1390f29313caabcd5967"),
plot: 'An intrepid reporter and his loyal friend battle a bizarre secret society of criminals known as The Vampires.',
genres: [ 'Action', 'Adventure', 'Crime' ],
runtime: 399,
rated: 'NOT RATED',
cast: [ 'Musidora', 'èdouardMathè', 'Marcel Lèvesque', 'Jean Aymè' ],
poster: 'https://m.media-amazon.com/images/M/MV5BMTc1NTY3NDIzNl5BMl5BanBnXkFtZTgwNTIyODg5MTE@._V1_SY1000_SX677_AL_.jpg',
title: 'Les vampires',
fullplot: 'An intrepid reporter and his loyal friend battle a bizarre secret society of criminals known as The Vampires.',
languages: [ 'French' ],
released: ISODate("1916-11-23T00:00:00.000Z"),
directors: [ 'Louis Feuillade' ],
writers: [ 'Louis Feuillade' ],
awards: { wins: 0, nominations: 1, text: '1 nomination.' },
lastupdated: '2015-09-02 00:24:27.333000000',
year: 1915,
imdb: { rating: 6.8, votes: 2878, id: 6206 },
countries: [ 'France' ],
type: 'movie',
tomatoes: {
viewer: { rating: 3.8, numReviews: 2118, meter: 82 },
dvd: ISODate("2000-05-16T00:00:00.000Z"),
critic: { rating: 8.8, numReviews: 13, meter: 100 },
lastUpdated: ISODate("2015-09-15T17:02:33.000Z"),
rotten: 0,
fresh: 13
    }
  },
.....

Explanation:

The said query in MongoDBretrieves all movies with full information from the 'movies' collection that have a runtime greater than 120 minutes.

In the find() method the $gt operator finds documents where the "runtime" field is greater than 120.

Improve this sample solution and post your code through Disqus.

Previous: Find Movies Released in 1893.
Next: Find movies with "Short" genre.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.