MongoDB MCQ Questions - Aggregation
This section focuses on "Aggregation" in MongoDB. These Multiple Choice Questions (MCQ) should be practiced to improve the MongoDB skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. The basic syntax of Aggregation is?
A. db.COLLECTION_NAME.aggregate ({key:1})
B. db.COLLECTION_NAME.aggregation (AGGREGATE_OPERATION)
C. db.COLLECTION_NAME.aggregate (AGGREGATE_OPERATION)
D. aggregate (AGGREGATE_OPERATION)
View Answer
Ans : C
Explanation: Basic syntax of aggregate() method is as follows :
>db.COLLECTION_NAME.aggregate(AGGREGATE_OPERATION)
2. Which of th following expression is used to calculates the average of all given values from all documents in the collection?
A. $sum
B. $avg
C. $min
D. $max
View Answer
Ans : B
Explanation: $avg: Calculates the average of all given values from all documents in the collection.
3. Which of th following expression is used to gets the maximum of the corresponding values from all documents in the collection?
A. $sum
B. $push
C. $min
D. $max
View Answer
Ans : D
Explanation: $max : Gets the maximum of the corresponding values from all documents in the collection
4. Which of th following expression is used to Inserts the value to an array in the resulting document?
A. $addToSet
B. $first
C. $push
D. $last
View Answer
Ans : C
Explanation: $push : Inserts the value to an array in the resulting document.
5. Which of th following expression is used to gets the first document from the source documents according to the grouping?
A. $addToSet
B. $first
C. $push
D. $last
View Answer
Ans : B
Explanation: $first : Gets the first document from the source documents according to the grouping. Typically this makes only sense together with some previously applied “$sort”-stage.
6. Which stages in aggregation framework Used to select some specific fields from a collection?
A. $project
B. $group
C. $limit
D. $unwind
View Answer
Ans : A
Explanation: $project : Used to select some specific fields from a collection.
7. What is true about $unwind stages in aggregation framework ?
A. It is used to unwind document that are using arrays.
B. When using an array, the data is kind of pre-joined and this operation will be undone with this to have individual documents again.
C. This stage we will increase the amount of documents for the next stage.
D. All of the above
View Answer
Ans : D
Explanation: $unwind : This is used to unwind document that are using arrays. When using an array, the data is kind of pre-joined and this operation will be undone with this to have individual documents again. Thus with this stage we will increase the amount of documents for the next stage.
8. What is true about $group stages in aggregation framework ?
A. This is a filtering operation and thus this can reduce the amount of documents that are given as input to the next stage.
B. This does the actual aggregation
C. Sorts the documents
D. None of the above
View Answer
Ans : B
Explanation: $group : This does the actual aggregation
9. What is true about $skip stages in aggregation framework ?
A. This is a filtering operation and thus this can reduce the amount of documents that are given as input to the next stage.
B. This limits the amount of documents to look at, by the given number starting from the current positions.
C. With this, it is possible to skip forward in the list of documents for a given amount of documents.
D. None of the above
View Answer
Ans : C
Explanation: $skip : With this, it is possible to skip forward in the list of documents for a given amount of documents.
10. Which stages in aggregation framework is a filtering operation and thus this can reduce the amount of documents that are given as input to the next stage?
A. $limit
B. $match
C. Both A and B can be used
D. None of the above
View Answer
Ans : B
Explanation: $match : This is a filtering operation and thus this can reduce the amount of documents that are given as input to the next stage.
Discussion