This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “Aggregation Mechanics”.
1. Which of the following stages cannot appear multiple times in a pipeline?
a) $regex
b) $reg
c) $match
d) $out
View Answer
Explanation: To use the $out stage, it must be the last stage in the pipeline.
2. Point out the correct statement.
a) To access variables in expressions, use a string that prefixes the variable name with $$$
b) Expressions can include field paths and system variables, literals, expression objects, and expression operators
c) To specify a field path, use a string that prefixes with a dollar sign % the field name or the dotted field name
d) All of the mentioned
View Answer
Explanation: Expressions can be nested.
3. Aggregation expressions use ______ path to access fields in the input documents.
a) mpath
b) dbpath
c) lpath
d) field
View Answer
Explanation: To specify a field path, use a string that prefixes with a dollar sign $ the field name or the dotted field name, if the field is in embedded document.
4. Which of the following statement is equivalent to “$$CURRENT.<field>”?
a) “$%<field>”
b) “%<field>”
c) “$$<field>”
d) “$<field>”
View Answer
Explanation: CURRENT is a system variable that defaults to the root of the current object in the most stages, unless stated otherwise in specific stages.
5. Point out the wrong statement.
a) Literals can be of any type
b) CURRENT cannot be rebound
c) MongoDB parses string literals that start with a dollar sign $
d) None of the mentioned
View Answer
Explanation: Along with the CURRENT system variable, other system variables are also available for use in expressions.
6. ______ binds variables for use in the specified expression.
a) $skip
b) $let
c) $bind
d) None of the mentioned
View Answer
Explanation: $let also returns the result of the expression.
7. ________ applies an expression to each item in an array and returns an array with the applied results.
a) $map
b) $geo
c) $geoRear
d) None of the mentioned
View Answer
Explanation: The $map expression has the following syntax: { $map: { input: <expressi>, as: <string>, in: <expression> } }
8. In the vars assignment block, ________ refers to the value of an externally defined variable low.
a) “$$low”
b) “$$lowin”
c) “$$1”
d) None of the mentioned
View Answer
Explanation: If low is not defined outside this $let expression block, the expression is invalid.
9. To avoid treating numeric or boolean literals as projection flags, use the _______ expression to wrap the numeric or boolean literals.
a) $literal
b) $bool
c) $unwin
d) None of the mentioned
View Answer
Explanation: The $literal expression has the following syntax: { $literal: <value> }
10. MongoDB treats the literals as projection flags, valid only in the _______ stage.
a) $project
b) $gmap
c) $match
d) None of the mentioned
View Answer
Explanation: Projection flags can be 1 or true to include the field.
Sanfoundry Global Education & Learning Series – MongoDB.
Here’s the list of Best Books in MongoDB.
- Apply for Programming Internship
- Check MongoDB Books
- Check Information Technology Books
- Practice Programming MCQs