logo

Crowdly

Browser

Add to Chrome

A collection recording the movies and the awards they have received has been cre...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

A collection recording the movies and the awards they have received has been created in MongoDB. The documents in the collection are designed such that an award will only be recorded if the movie won or was nominated for that particular award category. For example, according to the collection, the movie Matrix was nominated for three categories (best picture, best sound editing and best screenplay). It won only one category, best music. Only one result can be recorded for each category. If a movie was nominated and then won, the result will be recorded as won. If a movie was nominated and did not win, the result will be recorded as nominated. The wins field records the total number of awards won including the Oscar.

The following MongoDB shell command has been successfully executed.

db.movieAward.insertMany([

{"title":"Matrix",

"awards":{

    "oscars":[ {"award":"bestMusic","result":"won"},

        {"award":"bestPicture","result":"nominated"},

        {"award":"bestSoundEditing","result":"nominated"},

        {"award":"bestScreenplay","result":"nominated"}],

    "wins":56,

    "nominations":86,

    "text":"Won 1 Oscar. Another 56 wins and 86 nominations."

}},

{"title":"Kungfu Panda",

"awards":{

    "oscars":[{"award":"bestAnimatedFeature","result":"nominated"},

        {"award":"bestMusic","result":"won"},

        {"award":"bestPicture","result":"won"},

        {"award":"bestSoundEditing","result":"nominated"},

        {"award":"bestScreenplay","result":"nominated"}],

    "wins":12,

    "nominations":40,

    "text":"Won 2 Oscars. Another 56 wins and 86 nominations."

}}])

Two programmers Jane and Billy are writing a query to count all movies that won or was nominated for best picture at the Oscars.

Jane wrote the following: db.movieAward.find({"awards.oscars.award":"bestPicture"}).count()

Billy wrote the following:

db.movieAward.find(

  {$or:[{"awards.oscars":{$elemMatch:{"award":"bestPicture","result":"won"}}},

         {"awards.oscars":{$elemMatch:{"award":"bestPicture","result":"nominated"}}} ]

  }).count()

Although the codes are different, both approaches produce the same list of movies. True or False?

100%
0%
More questions like this

Want instant access to all verified answers on learning.monash.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome