What is the difference between a sparse index and a non-sparse index in MongoDB?
Answer: A
Question 2
We have the following indexes:
{ name: 1, founded_year: 1 }
{ tag_list: 1, is_active: 1 }
And the following documents:
{
_id: ObjectId("52cdef7c4bab8bd675297daa"),
name: "Sparter",
founded_year: 2007,
tag_list: ["gaming", "game", "wow"],
is_active: true
},
{
_id: ObjectId("52cdef7c4bab8bd675297da3"),
name: "Yahoo!",
founded_year: 1994,
tag_list: ["search", "webmail"],
is_active: true
}
Select the true statement.
Answer: B
Question 3
How can you insert a new document into a MongoDB collection named customers?
Answer: D
Question 4
Consider a MongoDB database containing a collection of documents representing product information for an e-commerce website. The documents have the following structure:
{ "username": "user3", "rating": 3, "comment": "Good but overpriced." }
]
}
Select the MongoDB aggregation pipeline that returns the average rating of all products grouped by brand. The result should include only brands with an average rating greater than or equal to 4. The output should have the following format:
Answer: D
Question 5
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.