What is the difference between a sparse index and a non-sparse index in MongoDB?
Answer: A
Question 2
Consider a MongoDB database containing a collection of documents representing online orders for an e-commerce website. The documents have the following structure:
Select an aggregation pipeline that returns the total sales amount by state and month, for orders placed in the year 2022. The result should have the following format:
Answer: A
Question 3
We have an accounts collection with the following document structure:
We need to use Aggregation Framework to find the distribution of products field. Sort the result set by decreasing total number of products.
Expected output:
[
{ _id: 'InvestmentStock', total: 1746 },
{ _id: 'CurrencyService', total: 742 },
{ _id: 'Brokerage', total: 741 },
{ _id: 'InvestmentFund', total: 728 },
{ _id: 'Commodity', total: 720 },
{ _id: 'Derivatives', total: 706 }
]
Which pipeline should you use?
Answer: B
Question 4
Consider a collection named students with the following document:
{
"_id" : ObjectId("5f0a7e80d8c9c7b5a48c49e1"),
"name" : "Alice",
"age" : 21,
"courses" : [
{
"name" : "Math",
"grade" : 89
},
{
"name" : "Science",
"grade" : 92
}
]
}
What is the query to update the grade of the "Math" course for the student with "_id" equal to ObjectId("5f0a7e80d8c9c7b5a48c49e1") to 95?
Answer: C
Question 5
In MongoDB, the $out operator is commonly used within an aggregation pipeline. Which of the following statements accurately describes the functionality and usage of the $out operator?