logo

Crowdly

Browser

Додати до Chrome

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

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

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%
Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на learning.monash.edu?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome