Why should you avoid indexing fields with very few unique values in MongoDB?
Because indexes on fields with low uniqueness (like boolean fields) do not improve query performance much and can add unnecessary overhead.
Click to reveal answer
beginner
What is a downside of indexing fields that are rarely used in queries?
Indexing rarely queried fields wastes storage and slows down write operations without benefiting read performance.
Click to reveal answer
intermediate
Why might you avoid indexing very large fields or fields with large data size?
Because large fields increase index size, which can slow down index maintenance and use more disk space.
Click to reveal answer
beginner
How can too many indexes affect MongoDB write performance?
Each index must be updated on writes, so having many indexes slows down insert, update, and delete operations.
Click to reveal answer
intermediate
When is it not recommended to create an index on a field that changes frequently?
Because frequent changes cause constant index updates, which can degrade write performance.
Click to reveal answer
Which type of field is generally NOT a good candidate for indexing in MongoDB?
AFields with many unique values
BFields frequently used in queries
CFields with very few unique values
DFields used in sorting
✗ Incorrect
Fields with very few unique values (like booleans) do not benefit much from indexing and add overhead.
What happens if you create too many indexes on a MongoDB collection?
AStorage space decreases
BRead operations become slower
CIndexes automatically merge
DWrite operations become slower
✗ Incorrect
Each index must be updated on writes, so too many indexes slow down inserts, updates, and deletes.
Why should you avoid indexing fields that rarely appear in queries?
AThey waste resources without benefit
BThey reduce storage needs
CThey improve query speed
DThey speed up writes
✗ Incorrect
Indexing rarely queried fields wastes storage and slows writes without improving query performance.
Which field characteristic can make an index very large and slow to maintain?
AFields with large data size
BFields with short strings
CFields with boolean values
DSmall numeric fields
✗ Incorrect
Large fields increase index size, making index updates slower and using more disk space.
When is it NOT recommended to index a field that changes frequently?
AWhen it is used in queries
BWhen frequent updates cause overhead
CWhen it is rarely updated
DWhen it is a primary key
✗ Incorrect
Frequent updates cause constant index maintenance, which slows down write performance.
Explain why indexing fields with low uniqueness can be harmful in MongoDB.
Think about how useful an index is if many documents share the same value.
You got /3 concepts.
Describe situations when you should avoid creating indexes to keep MongoDB efficient.
Consider both read and write performance impacts.
You got /4 concepts.
Practice
(1/5)
1. Which of the following is a good reason not to create an index on a MongoDB collection?
easy
A. The collection is very small and queries are fast without indexes.
B. The field is frequently used in queries to filter data.
C. The collection has millions of documents and needs fast lookups.
D. The field has many unique values and is often sorted.
Solution
Step 1: Understand index impact on small collections
Indexes add overhead and use space, so on very small collections, queries are already fast without them.
Step 2: Compare with other options
The other options describe good reasons to create indexes: frequent filtering, large collections, and fields with many unique values used in sorting.
Final Answer:
The collection is very small and queries are fast without indexes. -> Option A
Quick Check:
Small collections often don't need indexes [OK]
Hint: Avoid indexing tiny collections to save space and speed [OK]
Common Mistakes:
Thinking all collections always need indexes
Ignoring index overhead on small data
Confusing frequent query fields with rare ones
2. Which MongoDB command correctly creates an index on the email field of the users collection?
easy
A. db.users.create_index(email)
B. db.users.createIndex({email: 1})
C. db.users.index({email: 'asc'})
D. db.users.addIndex('email')
Solution
Step 1: Recall MongoDB index creation syntax
The correct method is createIndex with a document specifying field and order (1 for ascending).
Step 2: Check each option
db.users.createIndex({email: 1}) matches the correct syntax. The distractors use wrong method names or formats: create_index(email) (incorrect casing, underscore, and argument style), index({email: 'asc'}) (non-existent method), addIndex('email') (wrong method).
Final Answer:
db.users.createIndex({email: 1}) -> Option B
Quick Check:
Use createIndex({field: 1}) syntax [OK]
Hint: Use createIndex({field: 1}) to create ascending index [OK]
Common Mistakes:
Using wrong method names like create_index
Passing field name as string instead of object
Confusing ascending with string 'asc'
3. Given a collection logs with a field status that has only two values: 'success' or 'fail', what is the likely effect of creating an index on status?
medium
A. The index will use extra space but provide no significant speedup.
B. The index will cause errors because of low cardinality.
C. Queries filtering by status will be much faster due to the index.
D. The index will automatically compress the data to save space.
Solution
Step 1: Understand low cardinality fields and indexing
Fields with few distinct values (low cardinality) like 'success'/'fail' do not benefit much from indexes because many documents share the same value.
Step 2: Analyze options
Claims of much faster queries overestimate benefits for low cardinality. No errors occur from low cardinality indexes. Automatic data compression does not happen. The index uses extra space with no significant speedup.
Final Answer:
The index will use extra space but provide no significant speedup. -> Option A
Quick Check:
Low cardinality fields rarely benefit from indexes [OK]
Hint: Avoid indexing fields with few unique values [OK]
Common Mistakes:
Assuming all indexes speed up queries
Believing low cardinality causes errors
Thinking indexes compress data automatically
4. You created an index on the category field of a MongoDB collection, but queries filtering by category are still slow. What is a likely cause?
medium
A. MongoDB does not support indexing on string fields.
B. The index was created with the wrong field name syntax.
C. The category field has very few distinct values causing low index efficiency.
D. The collection is empty, so indexes do not work.
Solution
Step 1: Consider index usefulness on low distinct values
If category has few unique values, the index won't help much because many documents share the same value.
Step 2: Evaluate other options
Wrong field name syntax is unlikely if the index exists; MongoDB supports indexing on string fields; empty collections have no data to slow down queries.
Final Answer:
The category field has very few distinct values causing low index efficiency. -> Option C
Quick Check:
Low distinct values reduce index speedup [OK]
Hint: Check field cardinality if index doesn't speed queries [OK]
Common Mistakes:
Assuming all indexes always speed queries
Believing MongoDB can't index strings
Thinking empty collections cause index failure
5. You have a MongoDB collection orders with 100 documents. The status field has values 'pending', 'shipped', 'delivered'. You want to optimize queries filtering by status. What is the best indexing strategy?
hard
A. Create multiple indexes on each possible status value separately.
B. Create a single-field index on status to speed up queries.
C. Create a compound index on status and orderDate even if orderDate is rarely queried.
D. Do not create an index because the collection is small and status has few distinct values.
Solution
Step 1: Analyze collection size and field cardinality
The collection is very small (100 documents), and status has only three distinct values, so indexing will add overhead without much benefit.
Step 2: Evaluate indexing options
Create a single-field index on status to speed up queries. creates an index but likely unnecessary here. Create a compound index on status and orderDate even if orderDate is rarely queried. adds complexity with rarely used field. Create multiple indexes on each possible status value separately. is invalid as MongoDB does not create separate indexes per value.
Final Answer:
Do not create an index because the collection is small and status has few distinct values. -> Option D
Quick Check:
Small collections and low cardinality fields often don't need indexes [OK]
Hint: Skip indexes on small collections with few unique values [OK]
Common Mistakes:
Creating unnecessary indexes on small data
Misunderstanding compound index benefits
Trying to index each value separately
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.