text
Indextext
索引的名称On this page本页内容
Starting in version 4.2, for featureCompatibilityVersion set to 从版本4.2开始,对于设置为"4.2"
or greater, MongoDB removes the Index Name Length limit of 127 byte maximum. "4.2"
或更高版本的featureCompatibilityVersion
,MongoDB取消了最大127字节的索引名长度限制。In previous versions or MongoDB versions with featureCompatibilityVersion (fCV) set to 在"4.0"
, index names must fall within the limit.featureCompatibilityVersion
(fCV)设置为"4.0"
的早期版本或MongoDB版本中,索引名必须在限制范围内。
The default name for the index consists of each indexed field name concatenated with 索引的默认名称由与_text
. _text
连接的每个索引字段名称组成。For example, the following command creates a 例如,以下命令在text
index on the fields content
, users.comments
, and users.profiles
:content
、users.comments
和users.profiles
字段上创建text
索引:
db.collection.createIndex( { content: "text", "users.comments": "text", "users.profiles": "text" } )
The default name for the index is:索引的默认名称为:
"content_text_users.comments_text_users.profiles_text"
text
Indextext
索引的名称You can pass the 您可以将name
option to the db.collection.createIndex()
method:name
选项传递给db.collection.createIndex()
方法:
db.collection.createIndex( { content: "text", "users.comments": "text", "users.profiles": "text" }, { name: "MyTextIndex" } )
text
Indextext
索引Whether the text index has the default name or you specified a name for the text index, to drop the text index, pass the index name to the 无论db.collection.dropIndex()
method.text
索引具有默认名称还是您为text
索引指定了名称,要删除text
索引,请将索引名称传递给db.collection.dropIndex()
方法。
For example, consider the index created by the following operation:例如,考虑通过以下操作创建的索引:
db.collection.createIndex( { content: "text", "users.comments": "text", "users.profiles": "text" }, { name: "MyTextIndex" } )
Then, to remove this text index, pass the name 然后,要删除此文本索引,请将名称"MyTextIndex"
to the db.collection.dropIndex()
method, as in the following:"MyTextIndex"
传递给db.collection.dropIndex()
方法,如下所示:
db.collection.dropIndex("MyTextIndex")
To get the names of the indexes, use the 要获取索引的名称,请使用db.collection.getIndexes()
method.db.collection.getIndexes()
方法。