This version will reach end of life on Feb 2018. To upgrade, go to the Learn more about upgrading your version of MongoDB.

Create a text Index

You can create a text index on the field or fields whose value is a string or an array of string elements. When creating a text index on multiple fields, you can specify the individual fields or you can use wildcard specifier ($**).

Index Specific Fields

The following example creates a text index on the fields subject and content:

                             subject: "text",
                             content: "text"

This text index catalogs all string data in the subject field and the content field, where the field value is either a string or an array of string elements.

Index All Fields

To allow for text search on all fields with string content, use the wildcard specifier ($**) to index all fields that contain string content.

The following example indexes any string value in the data of every field of every document in collection and names the index TextIndex:

                           { "$**": "text" },
                           { name: "TextIndex" }


In order to drop a text index, use the index name. See Use the Index Name to Drop a text Index for more information.