Docs Menu
Docs Home
/ /

Text Indexes on Self-Managed Deployments

Note

This page describes text query capabilities for self-managed (non-Atlas) deployments. For data hosted on MongoDB Atlas, MongoDB offers an improved full-text query solution, Atlas Search and a vector search solution, Atlas Vector Search.

Text indexes support text search queries on fields with string content. Text indexes improve performance when searching for specific words or strings.

A collection can have only one text index, but that index may include multiple fields.

To create a text index, use the following prototype:

db.<collection>.createIndex(
{
<field1>: "text",
<field2>: "text",
...
}
)

Text indexes support $text queries on self-managed deployments. You must create a text index to use $text.

An online shop's clothing collection has a description field that contains a string of text describing each item. To find clothes made of "silk", create a text index on description and run a $text query for "silk". The search returns all documents mentioning "silk" in description.

To learn how to create and use text indexes, see:

This section describes text index details.

In a compound index with a text index key and other key types, only the text index field determines whether the index references a document. Other keys do not affect document references.

Text indexes can't cover a query.

Text indexes are always sparse. MongoDB ignores the sparse option when creating text indexes.

MongoDB does not add a text index entry for documents that lack the text index field, have null values, or have empty arrays.

Text indexes have these storage and performance characteristics:

  • Text indexes can consume significant RAM. They contain one index entry for each unique stemmed word in each indexed field for each document.

  • Building a text index is similar to building a large multikey index but takes longer than building an ordered (scalar) index on the same data.

  • When building large text indexes, ensure sufficient file descriptor limits. See recommended settings.

  • Text indexes impact write performance because MongoDB must add an index entry for each unique stemmed word in each indexed field of new documents.

  • Text indexes store individual words, not multi-word strings or word proximity information. Queries with multiple words run faster when the entire collection fits in RAM.

Back

Text Search Languages

On this page