mongodb - AWS文档数据库在查找查询中不使用elemMatch运算符中的索引?

标签 mongodb amazon-web-services aws-documentdb aws-documentdb-mongoapi

我对文档的数组字段使用单独的索引。查询文档时使用 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.

https://docs.aws.amazon.com/documentdb/latest/developerguide/functional-differences.html#functional-differences.elemMatch

示例查询:

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/

相关文章:

mongodb - 如何在Mongoose中按多个字段排序的列表中获取项目排名

javascript - mongo在javascript中解释函数

amazon-web-services - 将现有域的 DNS 服务迁移到 Amazon Route 53

python - AWS DocumentDB 语法不同于 MongoDB 的 UpdateMany

ssh-tunnel - 通过代理的 AWS DocumentDB

aws-documentdb-mongoapi - DocumentDB 简单查询超时,代码为 11601

mongodb - $near $unwind mongodb 地理空间

java - 如何在 Java MongoDB 中查询整个单词

amazon-web-services - beego running on AWS 发行

amazon-web-services - AWS Config - MaxNumberOfDeliveryChannelsExceededException