OPTIONS

Create text Index with Long NameΒΆ

The default name for the index consists of each indexed field name concatenated with _text. For example, the following command creates a text index on the fields content, users.comments, and users.profiles:

db.collection.ensureIndex(
                           {
                             content: "text",
                             "users.comments": "text",
                             "users.profiles": "text"
                           }
                         )

The default name for the index is:

"content_text_users.comments_text_users.profiles_text"

To avoid creating an index with a name that exceeds the index name length limit, you can pass the name option to the db.collection.ensureIndex() method:

db.collection.ensureIndex(
                           {
                             content: "text",
                             "users.comments": "text",
                             "users.profiles": "text"
                           },
                           {
                             name: "MyTextIndex"
                           }
                         )

Note

To drop the text index, use the index name. To get the name of an index, use db.collection.getIndexes().