Retrieve movies with awards from 'movies' collection
Retrieve all movies from the 'movies' collection that have received an award.
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(
{'awards.wins': {$gt: 0}
})
Output:
{ _id: ObjectId("573a1391f29313caabcd6e2a"), plot: "A newly wedded couple attempt to build a house with a prefabricated kit, unaware that a rival sabotaged the kit's component numbering.", genres: [ 'Short', 'Comedy' ], runtime: 25, cast: [ 'Buster Keaton', 'Sybil Seely' ], num_mflix_comments: 1, title: 'One Week', fullplot: "Buster and Sybil exit a chapel as newlyweds. Among the gifts is a portable house you easily put together in one week. It doesn't help that Buster's rival for Sybil switches the numbers on the crates containing the house parts.", languages: [ 'English' ], released: ISODate("1920-09-01T00:00:00.000Z"), directors: [ 'Edward F. Cline', 'Buster Keaton' ], rated: 'TV-G', awards: { wins: 1, nominations: 0, text: '1 win.' }, lastupdated: '2015-05-07 01:07:01.633000000', year: 1920, imdb: { rating: 8.3, votes: 3942, id: 11541 }, countries: [ 'USA' ], type: 'movie', tomatoes: { viewer: { rating: 4.3, numReviews: 752, meter: 91 }, lastUpdated: ISODate("2015-09-13T18:22:19.000Z") } },
Explanation:
The said query in MongoDB retrieves movies from the 'movies' collection in MongoDB that have received an award.
In the find() method the $exists operator filters movies that have the "awards" field present.
Improve this sample solution and post your code through Disqus.
Previous: Retrieve Movies with viewer rating higher than 4 on tomatoes.
Next: Find movies with nominations from 'movies' collection.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics