MongoDB Questions and Answers – Aggregation Mechanics

«
»

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

Answer: c
Explanation: To use the $out stage, it must be the last stage in the pipeline.

advertisement

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

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

Answer: d
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

Answer: d
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

Answer: b
Explanation: Along with the CURRENT system variable, other system variables are also available for use in expressions.

advertisement

6. ______ binds variables for use in the specified expression.
a) $skip
b) $let
c) $bind
d) None of the mentioned
View Answer

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

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

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

Answer: a
Explanation: The $literal expression has the following syntax: { $literal: <value> }

advertisement

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

Answer: a
Explanation: Projection flags can be 1 or true to include the field.

Sanfoundry Global Education & Learning Series – MongoDB.

Here’s the list of Best Reference Books in MongoDB.

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn