MongoDB Questions and Answers – Index Properties

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

1. ________ indexes expire documents after the specified number of seconds has passed since the indexed field value.
a) Hashed
b) Unique
c) Multikey
d) TTL
View Answer

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

2. Point out the correct statement.
a) If you build a TTL index in the foreground, MongoDB does not remove expired documents as soon as the index finishes building
b) The TTL index does guarantee that expired data will be deleted immediately upon expiration
c) Duration of the removal operation depends on the workload of your mongod instance
d) None of the mentioned
View Answer

Answer: c
Explanation: There may be a delay between the time a document expires and the time that MongoDB removes the document from the database.

3. When the TTL thread is active, you will see _______ operations in the output of db.currentOp().
a) delete
b) update
c) insert
d) none of the mentioned
View Answer

Answer: a
Explanation: A background thread in mongod reads the values in the index and removes expired documents from the collection.

4. The background task that removes expired documents runs every ________ seconds.
a) 15
b) 45
c) 60
d) 120
View Answer

Answer: c
Explanation: As a result, documents may remain in a collection during the period between the expiration of the document and the running of the background task.

advertisement
advertisement

5. Point out the wrong statement.
a) The unique constraint applies to separate documents in the collection
b) Unique index prevents separate documents from having the same value for the indexed key
c) Index does prevent a document from having multiple elements or embedded documents in an indexed array from having the same value
d) None of the mentioned
View Answer

Answer: c
Explanation: In the case of a single document with repeating values, the repeated value is inserted into the index only once.

6. On replica sets, the TTL background thread only deletes documents on _____________
a) primary
b) secondary
c) upadte
d) none of the mentioned
View Answer

Answer: a
Explanation: Secondary members replicate deletion operations from the primary.

7. You can combine the ________ constraint with the sparse index to filter these null values from the unique index and avoid the error.
a) Hashed
b) Unique
c) Sparse
d) Compound
View Answer

Answer: c
Explanation: If a document does not have a value for the indexed field in a unique index, the index will store a null value for this document.

8. You may not specify a unique constraint on a ______ index.
a) Hashed
b) Unique
c) Sparse
d) Compound
View Answer

Answer: a
Explanation: Because of the unique constraint, MongoDB will only permit one document that lacks the indexed field.

advertisement

9. Which of the following indexes are always sparse?
a) 2dsphere
b) 2d
c) geoHaystack
d) all of the mentioned
View Answer

Answer: d
Explanation: 2dsphere (version 2), 2d, geoHaystack, and text indexes are always sparse.

Sanfoundry Global Education & Learning Series – MongoDB.

advertisement

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.