$listSearchIndexes (aggregation)
On this page本页内容
Definition定义
$listSearchIndexes
Returns information about existing Atlas Search indexes on a specified collection.返回有关指定集合上现有Atlas Search索引的信息。
This command can only be run on a deployment hosted on MongoDB Atlas, and requires an Atlas cluster tier of at least M10.此命令只能在MongoDB Atlas上托管的部署上运行,并且需要至少M10的Atlas集群层。
Syntax语法
Command syntax:命令语法:
db.<collection>.aggregate(
[
{
$listSearchIndexes:
{
id: <indexId>,
name: <indexName>
}
}
]
)
Command Fields命令字段
$listSearchIndexes
takes either of the following fields:采用以下任一字段:
id | string | ||
name | string |
You cannot specify both 不能同时指定id
and name
. id
和name
。If you omit both the 如果同时省略id
and name
fields, $listSearchIndexes
returns information about all Atlas Search indexes on the collection.id
和name
字段,$listSearchIndexes
将返回集合上所有Atlas Search索引的信息。
Access Control访问控制
If your deployment enforces access control, the user running 如果部署强制执行访问控制,则运行$listSearchIndexes
must have the listSearchIndexes
privilege action on the database or collection:$listSearchIndexes
的用户必须对数据库或集合具有listSearchIndexes
权限操作:
{
resource: {
db : <database>,
collection: <collection>
},
actions: [ "listSearchIndexes" ]
}
The built-in 内置的read
role provides the the listSearchIndexes
privilege. The following example grants the read
role on the qa
database:read
角色提供listSearchIndexes
权限。以下示例授予qa
数据库上的read
角色:
db.grantRolesToUser(
"<user>",
[ { role: "read", db: "qa" } ]
)
Output输出
$listSearchIndexes
returns an array of documents. Each document in the array contains the following fields:返回一个文档数组。数组中的每个文档都包含以下字段:
id | string | |
name | string | |
status | string | |
queryable | boolean | |
latestDefinition | document |
Atlas Search Index StatusesAtlas搜索索引状态
The status
field in the $listSearchIndexes
output can be one of the following:$listSearchIndexes
输出中的status
字段可以是以下字段之一:
Status | |
---|---|
BUILDING | BUILDING state: BUILDING 状态:
BUILDING state: BUILDING 状态时:
|
FAILED | FAILED state due to an invalid index definition.FAILED 状态。 |
PENDING | |
READY | |
STALE | STALE state due to replication errors. STALE 状态。 |
Examples实例
These examples demonstrate how to:这些示例演示了如何:
Return All Search Indexes返回所有搜索索引Return a Single Search Index by Name按名称返回单个搜索索引Return a Single Search Index by id按id返回单个搜索索引
Return All Search Indexes返回所有搜索索引
The following example returns all Atlas Search indexes on the 以下示例返回movies
collection:movies
集合上的所有Atlas Search索引:
db.movies.aggregate(
[
{
$listSearchIndexes: { }
}
]
)
Sample output:样本输出:
[
{
id: '648b5397d8261c7d7d6f720e',
name: 'searchIndex01',
status: 'READY',
queryable: true,
latestDefinition: { mappings: { dynamic: true } }
},
{
id: '648b6110912df5513228465f',
name: 'frenchIndex01',
status: 'PENDING',
queryable: false,
latestDefinition: {
mappings: {
fields: {
subject: {
fields: { fr: { analyzer: 'lucene.french', type: 'string' } },
type: 'document'
}
}
}
}
}
]
The movies
collection contains two indexes:movies
集合包含两个索引:
searchIndex01
is in the处于READY
state.READY
状态。frenchIndex01
is in the处于PENDING
state.PENDING
状态。
Return a Single Search Index by Name按名称返回单个搜索索引
The following example returns the 以下示例返回searchIndex01
index on the movies
collection:movies
集合的searchIndex01
索引:
db.movies.aggregate(
[
{
$listSearchIndexes:
{
name: "searchIndex01"
}
}
]
)
Sample output:样本输出:
[
{
id: '648cb60e06f6780ba87a9913',
name: 'searchIndex01',
status: 'READY',
queryable: true,
latestDefinition: { mappings: { dynamic: true } }
}
]
Return a Single Search Index by id按id返回单个搜索索引
The following example returns the 以下示例根据索引id返回frenchIndex01
index based on the index id:frenchIndex01
索引:
db.movies.aggregate(
[
{
$listSearchIndexes:
{
id: "648b6110912df5513228465f"
}
}
]
)
Sample output:样本输出:
[
{
id: '648b6110912df5513228465f',
name: 'frenchIndex01',
status: 'PENDING',
queryable: true,
latestDefinition: {
mappings: {
fields: {
subject: {
fields: { fr: { analyzer: 'lucene.french', type: 'string' } },
type: 'document'
}
}
}
}
}
]
Learn More了解更多信息
To use a 要使用mongosh
method to view Atlas Search indexes, see db.collection.getSearchIndexes()
.mongosh
方法查看Atlas搜索索引,请参阅db.collection.getSearchIndexes()
。
To create Atlas Search indexes, see:要创建Atlas Search索引,请参阅:
Thedb.collection.createSearchIndex()
mongosh
methoddb.collection.createSearchIndex()
mongosh
方法ThecreateSearchIndexes
database commandcreateSearchIndexes
数据库命令