w3resource

Retrieve movies with complete information and IMDb rating higher than 7


Retrieve all movies from the 'movies' collection that have complete information and have an IMDb rating higher than 7.

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({ "imdb.rating": { $gt: 7 } })

Output:

{
    _id: ObjectId("573a1391f29313caabcd7a34"),
plot: 'A kept woman runs into her one-time fiancè and finds herself torn between love and comfort.',
genres: [ 'Drama', 'Romance' ],
runtime: 78,
rated: 'TV-PG',
cast: [
      'Edna Purviance',
      'Clarence Geldart',
      'Carl Miller',
      'Lydia Knott'
    ],
num_mflix_comments: 3,
poster: 'https://m.media-amazon.com/images/M/MV5BZjJiMTU2NGQtNWRkNi00ZjExLWExMTUtMmNkNTU0NzRlMTA3XkEyXkFqcGdeQXVyNjUwNzk3NDc@._V1_SY1000_SX677_AL_.jpg',
title: 'A Woman of Paris: A Drama of Fate',
fullplot: 'Marie St. Clair believes she has been jilted by her artist fiance Jean when he fails to meet her at the railway station. She goes off to Paris alone. A year later, mistress of wealthy Pierre Revel, she meets Jean again. Misinterpreting events she bounces back and forth between apparent security and true love.',
countries: [ 'USA' ],
released: ISODate("1923-11-04T00:00:00.000Z"),
directors: [ 'Charles Chaplin' ],
writers: [ 'Charles Chaplin' ],
awards: { wins: 1, nominations: 0, text: '1 win.' },
lastupdated: '2015-09-02 00:22:09.303000000',
year: 1923,
imdb: { rating: 7.1, votes: 3179, id: 14624 },
type: 'movie',
tomatoes: {
viewer: { rating: 3.7, numReviews: 886, meter: 78 },
dvd: ISODate("2004-03-02T00:00:00.000Z"),
critic: { rating: 7.4, numReviews: 11, meter: 91 },
lastUpdated: ISODate("2015-08-23T18:34:44.000Z"),
rotten: 1,
production: 'Criterion Collection',
fresh: 10
    }
  }

Explanation:

The said query in MongoDBretrieves movies from the 'movies' collection that have complete information and have an IMDb rating higher than 7.

In the find() method the $gt operator filters documents where the value of the 'imdb.rating' field is greater than 7.

Improve this sample solution and post your code through Disqus.

Previous: Retrieve movies with complete information and more than 1000 IMDb votes.
Next: Retrieve Movies with viewer rating higher than 4 on tomatoes.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/mongodb-exercises/mongodb-movies-collection-exercise-8.php