w3resource

Find Movies with "Fire" in fullplot


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".

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({
fullplot: { $regex: /fire/i } 
}, 
{ 
title: 1, 
languages: 1, 
fullplot: 1, 
released: 1, 
directors: 1, 
writers: 1, 
countries: 1 
})

Output:

  {
    _id: ObjectId("573a1393f29313caabcdc62b"),
title: 'Road to Zanzibar',
fullplot: `Chuck and his pal Fearless flee a South African carnival when their sideshow causes a fire. After several similar escapades, they've finally saved enough to return to the USA, when Chuck spends it all on a "lost" diamond mine. But that's only the beginning; before long, a pair of attractive con-women have tricked our heroes into financing a comic safari, featuring numerous burlesque jungle adventures...`,
languages: [ 'English', 'French' ],
released: ISODate("1941-04-11T00:00:00.000Z"),
directors: [ 'Victor Schertzinger' ],
writers: [
      'Frank Butler (screenplay)',
      'Don Hartman (screenplay)',
      'Don Hartman (based on a story by)',
      'Sy Bartlett (based on a story by)'
    ],
countries: [ 'USA' ]
  },
  {
    _id: ObjectId("573a1393f29313caabcdc6c6"),
title: 'That Hamilton Woman',
fullplot: `Sir William Hamilton, a widower of mature years, is British ambassador to the Court of Naples. Emma who comes for a visit with her mother wouldn't cut the grade with London society but she gets along well with the Queen of Naples. Emma likes being Lady Hamilton and life goes smoothly until Lord Nelson pays a visit. Sir William decides at first to let his young wife have her fling and pretends not to know what is going on. But the real life lovers, whose first screen romance was in "Fire Over England" (1937) have an even more burning passion for each other in this film.`,
languages: [ 'English', 'French', 'Italian' ],
released: ISODate("1941-04-30T00:00:00.000Z"),
directors: [ 'Alexander Korda' ],
writers: [
      'Walter Reisch (original screenplay)',
      'R.C. Sherriff (original screenplay)'
    ],
countries: [ 'UK' ]
  },
  {
    _id: ObjectId("573a1393f29313caabcdce23"),
title: 'The Memphis Belle: A Story of a Flying Fortress',
fullplot: 'Documentary about the 25th and last bombing mission of a B17, the "Memphis Belle". The "Memphis Belle" took part in a great bombing raid on sub-pens in Wilhelmshafen, Germany. On their way they encounterd heavy AA fire and interceptors.',
languages: [ 'English' ],
released: ISODate("1944-04-13T00:00:00.000Z"),
directors: [ 'William Wyler' ],
writers: [ 'Jerome Chodorov', 'Lester Koenig', 'William Wyler' ],
countries: [ 'USA' ]
  }
......

Explanation:

The said query in MongoDB returns movies with the title, languages, fullplot, released, directors, writers, and countries fields from the 'movies' collection in MongoDB that have the word "fire" in their fullplot field.

In the find() method the $regex operator performs a case-insensitive regular expression search for those movies that have the word "fire" in their fullplot field.

The projection parameter includes title, languages, fullplot, released, directors, writers, and countries in the output.

Improve this sample solution and post your code through Disqus.

Previous: Retrieve Movies Released Before 1900.
Next: Find Movies with "beer" in plot.

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://www.w3resource.com/mongodb-exercises/mongodb-movies-collection-exercise-17.php