MongoDB Questions and Answers – Aggregation Operations

«
»

This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “Aggregation Operations”.

1. _______ filters the document stream to allow only matching documents to pass unmodified into the next pipeline stage.
a) $regex
b) $reg
c) $match
d) None of the mentioned
View Answer

Answer: c
Explanation: $match uses standard MongoDB queries. For each input document, outputs either one document (a match) or zero documents (no match).

advertisement

2. Point out the wrong statement.
a) Documents do not pass through the stages in sequence
b) Pipeline stages appear in an multi dimensional array
c) $project reshapes each document in the stream, such as by adding new fields or removing existing fields
d) All of the mentioned
View Answer

Answer: c
Explanation: For each input document, outputs one document.

3. Which of the following can be used to implement field level redaction?
a) $skip
b) $limit
c) $match
d) $redact
View Answer

Answer: d
Explanation: $redact reshapes each document in the stream by restricting the content for each document based on information stored in the documents themselves.

4. ________ passes the first n documents unmodified to the pipeline where n is the specified limit.
a) $skip
b) $limit
c) $match
d) $redact
View Answer

Answer: b
Explanation: For each input document, outputs either one document (for the first n documents) or zero documents (after the first n documents).

advertisement

5. _______ reorders the document stream by a specified sort key.
a) $skip
b) $limit
c) $sort
d) None of the mentioned
View Answer

Answer: c
Explanation: Only the order changes; the documents remain unmodified.

6. Which of the following operator incorporates the functionality of $match, $sort, and $limit for geospatial data?
a) $geoSpatial
b) $geoNear
c) $geoRear
d) None of the mentioned
View Answer

Answer: b
Explanation: The output documents include an additional distance field and can include a location identifier field.

7. _____ Writes the resulting documents of the aggregation pipeline to a collection.
a) $out
b) $in
c) $output
d) None of the mentioned
View Answer

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

8. ________ deconstructs an array field from the input documents to output a document for each element.
a) $unwindelem
b) $unwind
c) $unwin
d) None of the mentioned
View Answer

Answer: c
Explanation: Each output document replaces the array with an element value.

9. Which of the following operator is related to geography of data?
a) $geoSpatial
b) $geoNear
c) $geoRear
d) None of the mentioned
View Answer

Answer: b
Explanation: $geoNear returns an ordered stream of documents based on the proximity to a geospatial point.

Sanfoundry Global Education & Learning Series – MongoDB.

advertisement

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