MongoDB Questions and Answers Part-29

1. _________ stores a log of the operations in a replica set.
a) oplog.rs
b) log.rs
c) oplog
d) all of the mentioned

Answer: a
Explanation: Built-in first-in-first-out property maintains the order of events while managing storage use.

2. ___________ is also used to pre-allocate space for an ordinary collection.
a) db.createCollection.
b) db.create
c) db.createColl
d) all of the mentioned

Answer: a
Explanation: MongoDB creates a collection implicitly when the collection is first referenced in a command.

3. Point out the wrong statement.
a) Queries need an index to return documents in insertion order
b) The options document creates a capped collection or preallocates space in a new ordinary collection
c) Capped collections have maximum size or document counts that prevent them from growing beyond maximum thresholds
d) None of the mentioned

Answer: a
Explanation: Capped collections guarantee preservation of the insertion order.

4. If you perform a ________ on a capped collection with no ordering specified, MongoDB guarantees that the ordering of results is the same as the insertion order.
a) find()
b) write()
c) modify()
d) none of the mentioned

Answer: a
Explanation: To retrieve documents in reverse insertion order, issue find() along with the sort() method with the $natural parameter set to -1.

5. Which of the following should is used to check whether collection is capped or not?
a) isCAP()
b) isCapped()
c) isColl()
d) none of the mentioned

Answer: b
Explanation: Use the isCapped() method to determine if a collection is capped, as: db.collection.isCapped().

6. ___________ convert a non-capped collection to a capped collection.
a) ToCapped
b) convertToCap
c) convertToCapped
d) none of the mentioned

Answer: c
Explanation: convertToCapped takes an existing collection (<collection>) and transforms it into a capped collection with a maximum size in bytes, specified by the size argument (<capped size>).

7. _________ command creates the capped collection and imports the data.
a) CollectionAsCapped
b) cloneCollection
c) cloneCollectionAsCapped
d) None of the mentioned

Answer: c
Explanation: MongoDB does not support the convertToCapped command in a sharded cluster.

8. Which of the following command obtains a global write lock and will block other operations until it has completed?
a) ToCapped
b) isCapped
c) convertToCapped
d) None of the mentioned

Answer: b
Explanation: If the capped size specified for the capped collection is smaller than the size of the original uncapped collection, then MongoDB will overwrite documents in the capped collection based on the insertion order, or first in, first out order.

9. Which of the following collection do not support the TTL property?
a) Compound indexes
b) Primary indexes
c) Composite indexes
d) All of the mentioned

Answer: a
Explanation: The TTL index is a single field index.

10. Point out the correct statement.
a) Data expiration is useful for some classes of information, including machine generated event data, logs, and session information
b) A special TTL index property supports the implementation of TTL collections
c) TTL collections make it possible to store data in MongoDB and have the mongod automatically remove data after a specified number of seconds or at a specific clock time
d) All of the mentioned

Answer: d
Explanation: The TTL feature relies on a background thread in mongod that reads the date-typed values in the index and removes expired documents from the collection.