A MongoDB text index supports keyword searches across string fields. It can index one or multiple fields, but each collection can have only one text index. MongoDB’s Atlas Search provides broader full-text search capabilities and is recommended over traditional text indexes when partial-value searches are required. section 7.2.4
Use a text index when an application needs:
- Case-insensitive searches for words and phrases. section 7.2.4
- Language-specific stemming and stop-word handling. section 7.2.4
- Relevance scoring and sorting by matching strength. section 7.2.4
Index movie titles and plots
Create one text index covering both fields, then search for matching terms and return the highest-scoring results first: db.movies.createIndex({ title: "text", fullplot: "text" }) db.movies.find( { $text: { $search: "Zone drinks" } }, { score: { $meta: "textScore" } } ).sort({ score: { $meta: "textScore" } }).limit(3) A search for “Zone drinks” can return the movie “Friend Zone” with a text relevance score. Prefixing a term with a minus sign excludes it, as in $search: "-Zone drinks". section 7.2.4
Listing 7.9 Text index prototype
db.<collection>.createIndex(
{
<field1>: "text",
<field2>: "text",
...
}
)
Use the prototype to adapt a text index to one or more string fields. section 7.2.4


