This version of the documentation is archived and no longer supported.

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" }