Which situation is NOT a good reason to create an index on a MongoDB collection field?
Think about how indexes affect write operations and storage.
Indexing fields that are frequently updated can slow down writes because the index must be updated each time. It's better to avoid indexing such fields unless necessary.
Consider a MongoDB collection with a field status that only has two possible values: 'active' or 'inactive'. What is the likely effect of creating an index on this status field?
Think about how selective the index is when the field has few distinct values.
Indexes on low-cardinality fields (few distinct values) usually do not improve query performance much and add overhead on writes and storage.
Which MongoDB command will cause a syntax error when trying to create an index?
db.users.createIndex({ age: 'ascending' })Check the valid values for index direction in MongoDB.
MongoDB accepts 1 or -1 for ascending or descending indexes. Strings like 'asc' or 'ascending' are invalid and cause syntax errors.
You have a MongoDB collection where the lastLogin field is updated every time a user logs in. You also query users by lastLogin date range sometimes. What is the best indexing strategy?
Consider the trade-off between read speed and write performance.
Indexing a field that is updated very often can degrade write performance significantly. If queries on that field are infrequent, it's better not to index it.
A developer created an index on the category field of a MongoDB collection. The category field contains many repeated values. Queries filtering by category are still slow. What is the most likely reason?
Think about how index selectivity affects query speed.
Indexes on fields with many repeated values (low cardinality) do not help much because the database still scans many documents. This makes queries slow despite the index.