Text Index
noun
say it: “TEKST IN-deks” /tɛkst ˈɪndɛks/
A MongoDB index on text fields that lets a search find the documents containing certain words.
What is a text index in MongoDB?
A text index covers a collection's text fields so a $text search can find whole words in them, in any case and in any form, so tomato finds "Tomatoes". A collection can have only one, though it may cover several fields.
await vendors.createIndex({ name: "text", products: "text" });
const found = await vendors.find({ $text: { $search: "honey" } }).toArray();
console.log(found.map((v) => v.name)); // [ 'Bee Happy Honey' ]
In a sentence
- “After adding a text index on name and products, a search for honey found Bee Happy Honey.”
- “Without a text index, a $text query stops with an error.”
Level: Journeyman · More MongoDB terms at this level
Updated