MongoDB Questions and Answers – Read Operations – 2

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

1. Which of the following flag can be set by mongo shell?
a) Timeout
b) noTimeout
c) Time
d) None of the mentioned
View Answer

Answer: b
Explanation: By default, the server will automatically close the cursor after 10 minutes of inactivity or if client has exhausted the cursor.

2. Point out the correct statement.
a) Intervening read operations on a document may result in a cursor that returns a document more than once if that document has changed
b) The MongoDB server returns the query results in batches
c) Subsequent batch size is 50 megabytes
d) None of the mentioned
View Answer

Answer: b
Explanation: For most queries, the first batch returns 101 documents or just enough documents to exceed 1 megabyte.

3. Which of the following will display complete list of available cursor flags?
a) cursor.Option()
b) cursor.addOption()
c) cursor.addOptions()
d) all of the mentioned
View Answer

Answer: b
Explanation: You should either close the cursor manually or exhaust the cursor.

4. To describe the message structure, a ________ like struct is used.
a) Pascal
b) C++
c) C
d) Java
View Answer

Answer: c
Explanation: The standard message header is typed as MsgHeader. Integer constants are in capitals (e.g. ZERO for the integer value of 0).

advertisement
advertisement

5. Point out the wrong statement.
a) The MongoDB Wire Protocol is a simple socket-based, request-response style protocol
b) For queries that include a sort operation without an index, the server must load all the documents in memory to perform the sort before returning any results
c) Clients communicate with the database server through a regular TCP/IP socket
d) All of the mentioned
View Answer

Answer: b
Explanation: MongoDB can perform sort operations without an index, but if an index is not available, it will perform an in-memory sort on the result set. All the other options are correct, such as the MongoDB Wire Protocol is a socket-based protocol, clients communicate with MongoDB servers through a regular TCP/IP socket.

6. ______________ specifies the number of documents to return in each batch of the response from the MongoDB instance.
a) cursor.batchSize(size)
b) cursor.Size(size)
c) cursor.batch(size)
d) all of the mentioned
View Answer

Answer: a
Explanation: Specifying 1 or a negative number is analogous to using the limit() method.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

7. The __________ method returns a document that includes a metrics field.
a) db.serverStats()
b) db.serverStatus()
c) db.status()
d) all of the mentioned
View Answer

Answer: b
Explanation: The metrics field contains a cursor with number of timed out cursors since the last server restart.

8. ____________ is a client or database-generated identifier that uniquely identifies this message.
a) messageLength
b) responseTo
c) requestID
d) all of the mentioned
View Answer

Answer: c
Explanation: For the case of client-generated messages, it will be returned in the responseTo field of the OP_REPLY message.

advertisement

9. Which of the following operator is not very selective?
a) $nine
b) $nin
c) $ain
d) None of the mentioned
View Answer

Answer: b
Explanation: The inequality operators $nin and $ne are not very selective since they often match a large portion of the index.

10. An index cannot cover a query on a _______ collection when run against a mongos if the index does not contain the shard key.
a) vertical
b) sharded
c) horizontal
d) none of the mentioned
View Answer

Answer: b
Explanation: MongoDB can both match the query conditions and return the results using only the index.

advertisement

Sanfoundry Global Education & Learning Series – MongoDB.

Here’s the list of Best Books in MongoDB.

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.