使用 mongodb java 驱动程序时,queryPlanner 中缺少字段 queryHash 和 planCacheKey

问题描述

在本地开发期间,我尝试使用解释来分析 mongodb 查询。我正在使用以下代码段来提取解释输出

使用 MongoDB 版本 4.2 和 mongo-java-driver 版本 3.12.2

    Document explainDocument = new Document();
    explainDocument.put("find",collectionName);
    explainDocument.put("filter",queryObject);

    Document command = new Document();
    command.put("explain",explainDocument);

    Document explainResult = mongoTemplate.executeCommand(command);

这很好用,在explainResult的queryPlanner字段中,我得到以下输出

{
  "plannerVersion": 1,"namespace": "mydb.myCollection","indexFilterSet": false,"parsedQuery": { ... },"winningPlan": { ... },"rejectedplans": [
    
  ]
}

但是当我在 mongo shell 上运行相同的查询db.getCollection('myCollection').find({...query}).explain() 我明白了

{
    "plannerVersion" : 1,"namespace" : "mydb.myCollection","indexFilterSet" : false,"parsedQuery" : { ... },"queryHash" : "B6F93250","planCacheKey" : "5BE08F08","winningPlan" : { ... },"rejectedplans" : []
}

我也得到 queryHashplanCacheKey。我怎样才能使用我的 java 驱动程序获得这些?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)