MongoDB Questions and Answers – Indexing Strategies

«
»

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

1. _________ operations that use an index often have better performance than those that do not use an index.
a) Select
b) Update
c) Delete
d) Sort
View Answer

Answer: d
Explanation: In MongoDB, sort operations can obtain the sort order by retrieving documents based on the ordering in an index.

2. Point out the wrong statement.
a) The query scans the index and the collection
b) An index supports a query when the index contains all the fields scanned by the query
c) Creating indexes that support queries results in greatly increased query performance
d) None of the mentioned
View Answer

Answer: a
Explanation: The query scans the index and not the collection.

advertisement

3. A prefix of a _______ index is a subset that consists of one or more keys at the start of the index key pattern.
a) unique
b) primary
c) compound
d) none of the mentioned
View Answer

Answer: b
Explanation: If the sort keys correspond to the index keys or an index prefix, MongoDB can use the index to sort the query results.

4. Sort operations that do not use an index will abort when they use _______ megabytes of memory.
a) 16
b) 32
c) 64
d) All of the mentioned
View Answer

Answer: b
Explanation: If the query planner cannot obtain the sort order from an index, it will sort the results in memory.

advertisement
advertisement

5. Point out the correct statement.
a) If you only ever query on a single key in a given collection, then you need to create just multikey index for that collection
b) If you sometimes query on only one key and at other times query on that key combined with a second key, then creating a compound index is more efficient than creating a single-key index
c) The choice between creating compound indexes that support your queries or relying on index intersection is independent of specifics of your system
d) None of the mentioned
View Answer

Answer: b
Explanation: MongoDB will use the compound index for both queries.

6. An index can support sort operations on a non-prefix subset of the index key pattern using _________ condition.
a) predicate
b) selection
c) equality
d) none of the mentioned
View Answer

Answer: c
Explanation: Query must include equality conditions on all the prefix keys that precede the sort keys.

advertisement

7. __________ method provides a wrapper around the totalIndexSize output of the collStats (i.e. db.collection.stats()) operation.
a) db.collection.totalallIndexSize()
b) db.collection.totalIndexSizeAll()
c) db.collection.totalIndexSize()
d) all of the mentioned
View Answer

Answer: c
Explanation: To check the size of your indexes, use the db.collection.totalIndexSize() helper, which returns data in bytes.

8. Indexes do not have to fit entirely into ______ in all cases.
a) ROM
b) RAM
c) Secondary Storage
d) None of the mentioned
View Answer

Answer: a
Explanation: There are some limited cases where indexes do not need to fit in memory.

advertisement

9. ________ is the ability of a query to narrow results using the index.
a) Causality
b) Cardinality
c) Selectivity
d) All of the mentioned
View Answer

Answer: b
Explanation: Effective indexes are more selective and allow MongoDB to use the index for a larger portion of the work associated with fulfilling the query.

Sanfoundry Global Education & Learning Series – MongoDB.

advertisement

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