We have a movies collection with the following document structure:
{
_id: ObjectId("573a1390f29313caabcd6223"),
genres: [ 'Comedy', 'Drama', 'Family' ],
title: 'The Poor Little Rich Girl',
released: ISODate("1917-03-05T00:00:00.000Z"),
year: 1917,
imdb: { rating: 6.9, votes: 884, id: 8443 }
},
{
_id: ObjectId("573a13e3f29313caabdc08a4"),
genres: [ 'Horror', 'Thriller' ],
title: 'Mary Loss of Soul',
year: 2014,
imdb: { rating: '', votes: '', id: 2904798 }
}
We need to use Aggregation Framework to calculate the following aggregates:
average imdb rating
minimum imdb rating
maximum imdb rating
Expected output:
[
{
_id: null,
avg_rating: 6.6934040649367255,
min_rating: 1.6,
max_rating: 9.6
}
]
Please note that some documents have "" (empty string) for the field "imdb.rating". Exclude these documents before aggregation.
Which pipeline should you use?
Answer: C
Question 2
Consider the following scenario: You have a MongoDB collection named users that stores user information. Each document in the collection has the following structure:
{
"_id": ObjectId("609fe4b5728ad805aef1a88d"),
"name": "John Doe",
"age": 30,
"email": "johndoe@example.com",
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zipcode": "10001"
}
}
You need to retrieve all the documents from the users collection and convert them to an array format. Which of the following MongoDB queries should you use for this task?
Answer: B
Question 3
Suppose you have a reviews collection with the following index:
{ stars: 1, votes: 1 }
Which of the following queries would be a covered query?
Answer: D
Question 4
Suppose you insert the following documents into a companies collection:
db.companies.insertMany([
{"name": "Facebook"},
{"name": "X"}
])
Select all true statements about this command. (Select three)
Answer: C,D,E
Question 5
Given the following documents in a collection:
{ _id: 1, n: [1,2,5], p: 0.75, c: 'Green' },
{ _id: 2, n: 'Orange', p: 'Blue', c: 42, q: 14 },
{ _id: 3, n: [1,3,7], p: 0.85, c: 'Orange' }
Which two documents can successfully be added in the same collection? (Select two)