MongoDB Questions and Answers – Data from Collections

«
»

This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “Data from Collections”.

1. 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
View Answer

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

advertisement

2. 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
View Answer

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.

3. If the indexed field in a document is not a _____ or an array that holds a date value(s), the document will not expire.
a) DATE
b) TIME
c) DATETIME
d) All of the mentioned
View Answer

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

advertisement
advertisement

4. Point out the correct statement.
a) TTL indexes expire documents after the specified number of seconds has passed since the indexed field value
b) TTL indexes are special compound indexes
c) If a document does not contain the indexed field, the document will expire
d) None of the mentioned
View Answer

Answer: a
Explanation: The expiration threshold is the indexed field value plus the specified number of seconds.

5. Secondary members replicate _________ operations from the primary.
a) Update
b) Drop
c) Insert
d) None of the mentioned
View Answer

Answer: d
Explanation: On replica sets, the TTL background thread only deletes documents on the primary.

advertisement

6. A collection with a TTL index has __________ enabled.
a) usePowerOf3Sizes
b) usePowerOf2Sizes
c) usePowerOf4Sizes
d) none of the mentioned
View Answer

Answer: b
Explanation: As a result of enabling usePowerOf2Sizes, MongoDB must allocate more disk space relative to data size.

7. Which field does not support TTL indexes?
a) _identity
b) _option
c) _id
d) None of the mentioned
View Answer

Answer: c
Explanation: You cannot create a TTL index on a capped collection because MongoDB cannot remove documents from a capped collection.
advertisement

8. You cannot use _________ to change the value of expireAfterSeconds of an existing index.
a) createIndex()
b) dropIndex()
c) removeIndex()
d) none of the mentioned
View Answer

Answer: a
Explanation: Instead use the collMod database command in conjunction with the index collection flag. Otherwise, to change the value of the option of an existing index, you must drop the index first and recreate.

9. You cannot create a TTL index on a ________ collection.
a) Sharded
b) Capped
c) Primary
d) None of the mentioned
View Answer

Answer: b
Explanation: MongoDB cannot remove documents from a capped collection.

advertisement

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