MongoDB Questions and Answers Part-11

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

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

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

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

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).

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

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

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

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

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

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

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

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

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