You are tasked with developing a high-performance application using MongoDB as your primary database. The application heavily relies on queries that retrieve user profiles based on user names and their location. Given this requirement, you decide to implement a strategy to make these queries more efficient. What strategy should you implement to ensure these queries are covered queries?
Answer: D
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
You have two collections in your MongoDB database: students and grades. The students collection contains the following document:
{
"_id": ObjectId("64d5b0e5c9d95a76ac3ebed2"),
"student_id": 1,
"name": "Alice"
}
The grades collection contains the following documents:
{
"_id": ObjectId("64d5b0e5c9d95a76ac3ebed3"),
"student_id": 2,
"course": "Math",
"grade": "A"
},
{
"_id": ObjectId("64d5b0e5c9d95a76ac3ebed4"),
"student_id": 2,
"course": "Science",
"grade": "B"
}
You run the following aggregation query to retrieve students along with their grades:
db.students.aggregate([
{
$lookup: {
from: "grades",
localField: "student_id",
foreignField: "student_id",
as: "grades_details"
}
}
])
What will be the structure of the documents returned by this aggregation query for the student with student_id: 1?
Answer: B
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
In MongoDB, which statement accurately describes a typical task for a MongoDB developer related to schema validation?