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
View Answer

Answer: a
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
View Answer

Answer: c
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
View Answer

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

advertisement
advertisement

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
View Answer

Answer: b
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
View Answer

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

Note: Join free Sanfoundry classes at Telegram or Youtube

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

Answer: c
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
View Answer

Answer: b
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.
advertisement

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
View Answer

Answer: c
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
View Answer

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

advertisement

Sanfoundry Global Education & Learning Series – MongoDB.

Here’s the list of Best Books in MongoDB.

To practice all areas of MongoDB for entrance exams, Here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.