我对文档的数组字段使用单独的索引。查询文档时使用 elemMatch 运算符。但是当我尝试运行解释命令时,它显示索引未使用。
我得到以下解释查询结果:
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "mydb.mycollection",
"winningPlan" : {
"stage" : "COLLSCAN"
}
},
"serverInfo" : {
"host" : "xxxxxx",
"port" : xxxxx,
"version" : "3.6.0"
},
"ok" : 1.0
}
这意味着它没有使用我为此集合创建的索引。
aws document 是否不在 elemMatch 运算符中使用数组索引。 ?
最佳答案
AWS DocumentDB 目前不支持在使用 $elemMatch 运算符时使用索引。
$distinct, $elemMatch, and $lookup Indexing
Amazon DocumentDB does not currently support the ability to use indexes with the $distinct, $elemMatch, and $lookup operators. As a result, utilizing these operators will result in collection scans. Performing a filter or match before utilizing one of these operators will reduce the amount of data that needs to be scanned, and thus can improve performance.
示例查询:
db.getCollection("collection").find(
{
"MyArrayField" : {
"$elemMatch" : {
"MyFieldOfObjectInArray" : UUID("11111111-1111-1111-111-111111111111")
}
}
}
).hint("Multi_key_index").explain();
返回错误:
无法对此查询使用提示。索引是多键索引或稀疏索引,并且查询未针对使用此索引进行优化。
关于mongodb - AWS文档数据库在查找查询中不使用elemMatch运算符中的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59456885/