How does MongoDB handle sorting on fields that contain missing values (i.e., values that are not present in all documents in the collection)?
Answer: C
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
How can you insert a new document into a MongoDB collection named customers?
Answer: D
Question 4
Suppose you have a products collection with an index:
{ product_category: 1 }
For which of the following queries can MongoDB look at only a subset of the index entries, rather than all of the index entries?
Answer: D
Question 5
Consider a MongoDB collection named orders which has documents in the following format:
{
"_id" : ObjectId("5f5b0d2f3e3dfbcc11c84444"),
"orderId" : 1001,
"customerId" : 200,
"items" : [
{
"productId" : 101,
"quantity" : 2
},
{
"productId" : 102,
"quantity" : 1
}
],
"totalAmount" : 250,
"status" : "Pending"
}
What is the correct syntax to find and update the first document in the orders collection where "status" is "Pending", and change the "status" field to "Completed" using the findAndModify method?