What index types should I know?
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn What index types should I know?
Definition:
MongoDB offers different index types because equality lookup, array search, text search, uniqueness and expiry have different needs. A compound index orders several fields together, while a partial index includes only documents matching a condition. TTL indexes support eventual cleanup rather than precise scheduling.
Key points:
-
Single-field: one field; compound: multiple fields; multikey: array values.
-
Unique: prevents duplicate indexed values; partial: indexes only matching documents.
-
Text: word search; TTL: expires documents asynchronously, not at an exact second.
-
A unique index has specific behavior for missing/null fields and arrays, so test it against the actual optional-field model.
Interview point:
- Choose an index from a query or data rule; do not add every index type just because it exists.
Adapted from 04_MONGODB_MONGOOSE.md · “What index types should I know?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.