MongoDB โ Specialized Indexes: Multikey, Text & Hashed
Explore Multikey indexes for array fields, Text indexes for full-text search, and Hashed indexes for sharding.
1Multikey Indexes (Array Fields)
When you create an index on a field containing an array, MongoDB automatically creates a Multikey Index by indexing each element in the array separately.
Multikey Index Example
// Document: { title: "Post", tags: ["js", "mongo"] }
db.posts.createIndex({ tags: 1 }); // Automatically becomes a Multikey index!
2Text Indexes for Full-Text Search
Text Index & Search
// 1. Create text index on title and description
db.articles.createIndex({ title: "text", description: "text" });
// 2. Search using $text operator
db.articles.find({ $text: { $search: "mongodb tutorial" } });