# MongoDB Questions and Answers – Pipeline Operators – 2

«
»

This set of MongoDB Questions for entrance exams focuses on “Pipeline Operators – 2”.

1. \$sum is an accumulator operator available only in the _______ stage.
a) \$group
b) \$sets
c) \$accumulator
d) None of the mentioned

Explanation: \$sum calculates and returns the sum of all the numeric values.

2. Point out the wrong statement.
a) \$avg is an accumulator operator available only in the \$group stage
b) \$sum accumulator can be used to compute the total amount and count for each group of documents
c) \$avg ignores numeric values
d) All of the mentioned

Explanation: \$avg returns the average value of the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key.

3. Which of the following ignores non numeric values?
a) \$order
b) \$sum
c) \$asc
d) None of the mentioned

Explanation: \$sum returns a sum for each group. Ignores non-numeric values.

4. When using \$first in a \$group stage, the \$group stage should follow a _______ stage to have the input documents in a defined order.
a) \$order
b) \$sort
c) \$asc
d) None of the mentioned

Explanation: \$sort takes a document that specifies the field(s) to sort by and the respective sort order.

5. Which of the following returns the value that results from applying an expression to the last document?
a) \$end
b) \$last
c) \$max
d) All of the mentioned

Explanation: \$last has the following syntax: { \$last: <expression> }.

6. __________ returns the highest value from the group of values in documents.
a) \$end
b) \$last
c) \$max
d) \$maximum

Explanation: \$max returns the highest value that results from applying an expression to each document in a group of documents that share the same group by key.

7. Which of the following is syntax for calculating minimum value?
a) { \$minimum: <int> }
b) { \$min: <expression>}
c) { \$minimum: <expression> }
d) None of the mentioned

Explanation: \$min returns the lowest value that results from applying an expression to each document in a group of documents that share the same group by key.

8. If all documents for the \$min operation have null value for the field or are missing the field, the \$min operator returns ____ for the minimum value.
a) 1
b) 0
c) null
d) none of the mentioned

Explanation: If some, but not all, documents for the \$min operation have either a null value for the field or are missing the field, the \$min operator only considers the non-null and the non-missing values for the field.

9. \$addToSet returns an array of all _______ values that results from applying an expression to each document.
a) unique
b) non unique
c) distinct
d) all of the mentioned

Explanation: Order of the elements in the output array is unspecified. 