MongoDB Questions and Answers – Aggregation Pipeline

«
»

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

1. Aggregation pipeline was introduced in MongoDB version ______
a) 2.1
b) 2.2
c) 2.4
d) 3.0
View Answer

Answer: b
Explanation: The aggregation pipeline provides an alternative to map-reduce.

advertisement

2. Point out the wrong statement.
a) Aggregation pipeline have some limitations on value types and result size
b) The aggregation pipeline is a framework for data aggregation modeled on the concept of data processing pipelines
c) Documents enter a multi-stage pipeline that transforms the documents into an aggregated results
d) All of the mentioned
View Answer

Answer: d
Explanation: The MongoDB aggregation pipeline consists of stages.

3. ________ calculates aggregate values for the data in a collection.
a) db.collection.aggregate
b) db.collection.agg
c) db.collection.pipeline
d) all of the mentioned
View Answer

Answer: a
Explanation: In the mongo shell, if the cursor returned from the db.collection.aggregate() is not assigned to a variable using the var keyword, then the mongo shell automatically iterates the cursor up to 20 times.

advertisement
advertisement

4. Cursors returned from aggregation only supports cursor methods like ________________
a) cursor.hasNext()
b) cursor.Next()
c) cursor.has()
d) all of the mentioned
View Answer

Answer: a
Explanation: cursor.hasNext() returns true if the cursor returned by the db.collection.find() query can iterate further to return more documents.

5. Point out the wrong statement.
a) Some pipeline stages may generate new documents or filter out documents
b) Pipeline stages do need to produce one output document for every input document
c) Pipeline stages can appear multiple times in the pipeline
d) None of the mentioned
View Answer

Answer: b
Explanation: Pipeline stages do need to produce one output document for every input document.

advertisement

6. ______ can be used to iterate the cursor of document results returned by db.collection.find().
a) it
b) next
c) cur
d) none of the mentioned
View Answer

Answer: a
Explanation: The mongo shell iterates the returned cursor automatically to print the results.

7. To handle large datasets, set _________ option to true to enable writing data to temporary files.
a) enableDiskUse
b) allowDiskUse
c) validateDiksUse
d) none of the mentioned
View Answer

Answer: b
Explanation: In the mongo shell, when you assign the cursor returned from the find() method to a variable using the var keyword, the cursor does not automatically iterate.

advertisement

8. Syntax for specifying an initial batch size for the cursor is ________________
a) cursor: { batchSize: <string> }
b) cursor: { batchSize: <int> }
c) cur: { batchSize: <int> }
d) none of the mentioned
View Answer

Answer: b
Explanation: A batchSize of 0 means an empty first batch and is useful for quickly returning a cursor or failure message without doing significant server-side work.

9. Query shape consists of a combination of query, sort, and _________ specifications.
a) selection
b) projection
c) collection
d) none of the mentioned
View Answer

Answer: c
Explanation: If an index filter exists for a given query shape, the optimizer only considers those indexes specified in the filter.

advertisement

10. Which of the following method is overrided by Index filters?
a) hint
b) plan
c) execute
d) all of the mentioned
View Answer

Answer: a
Explanation: When an index filter exists for the query shape, MongoDB ignores the hint().

Sanfoundry Global Education & Learning Series – MongoDB.

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

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!

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
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 | Youtube | Instagram | Facebook | Twitter