MongoDB Questions and Answers – Index Types – 1

«
»

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

1. To support ________ based sharding, MongoDB provides a hashed index type.
a) primary
b) root
c) hash
d) all of the mentioned
View Answer

Answer: c
Explanation: These indexes have a more random distribution of values along their range, but only support equality matches and cannot support range-based queries.

2. Point out the correct statement.
a) Whether the use of a compound index or the use of an index intersection is more efficient depends on the particular query and the system
b) Certain restrictions apply to indexes, such as the length of the index keys or the number of indexes per collection
c) For queries that specify compound query conditions, if one index can fulfill a part of a query condition, and another index can fulfill another part of the query condition, then MongoDB can use the intersection of the two indexes to fulfill the query
d) None of the mentioned
View Answer

Answer: d
Explanation: In general, each index intersection involves two indexes; however, MongoDB can employ multiple/nested index intersections to resolve a query.

advertisement

3. ________ index type, which indexes the hash of the value of a field.
a) Hashed
b) Unique
c) Multikey
d) None of the mentioned
View Answer

Answer: a
Explanation: Hashed indexes support equality matches and cannot support range-based queries.

4. The _________ property for an index causes MongoDB to reject duplicate values for the indexed field.
a) Hashed
b) Unique
c) Multikey
d) None of the mentioned
View Answer

Answer: c
Explanation: Other than the unique constraint, unique indexes are functionally interchangeable with other MongoDB indexes.

advertisement
advertisement

5. Point out the wrong statement.
a) TTL index is ideal for certain types of information like machine generated event data, logs, and session information that only need to persist in a database for a finite amount of time
b) You cannot combine the sparse index option with the unique index option
c) TTL indexes are special indexes that MongoDB can use to automatically remove documents from a collection after a certain amount of time
d) None of the mentioned
View Answer

Answer: b
Explanation: You can combine to reject documents that have duplicate values for a field but ignore documents that do not have the indexed key.

6. The ______ property of an index ensures that the index only contain entries for documents that have the indexed field.
a) Hashed
b) Unique
c) Sparse
d) None of the mentioned
View Answer

Answer: c
Explanation: The index skips documents that do not have the indexed field.

advertisement

7. MongoDB can use the _________ of indexes to fulfill queries.
a) union
b) intersection
c) projection
d) none of the mentioned
View Answer

Answer: b
Explanation: The $project takes a document that can specify the inclusion of fields, the suppression of the _id field, the addition of new fields, and the resetting the values of existing fields.

8. Which of the following method is to verify whether MongoDB used index intersection?
a) explain()
b) analyze()
c) intersect()
d) none of the mentioned
View Answer

Answer: a
Explanation: To determine if MongoDB used index intersection, run explain(); the results of explain() will include either an AND_SORTED stage or an AND_HASH stage.

advertisement

9. An index prefix is a subset of a ______ index, consisting of one or more keys starting from the beginning of the index.
a) Hashed
b) Unique
c) Sparse
d) Compound
View Answer

Answer: d
Explanation: With index intersection, MongoDB can use an intersection of either the entire index or the index prefix.

10. Index __________ does not eliminate the need for creating compound indexes.
a) union
b) addition
c) intersection
d) all of the mentioned
View Answer

Answer: c
Explanation: Compound index may not support a query condition that does not include the index prefix keys or that specifies a different sort order.

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