Skip to content

Commit 357266b

Browse files
Merge pull request #8 from mongodb-developer/fix/quick-fix
added index name to console log.
2 parents 9522750 + 4a48ab6 commit 357266b

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

java/105_aggregation_pipeline_explain.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,21 @@
171171
" List.of(match(filter))\n",
172172
").explain(ExplainVerbosity.EXECUTION_STATS);\n",
173173
"\n",
174+
"var winningPlan = explainResult\n",
175+
" .get(\"queryPlanner\", Document.class)\n",
176+
" .get(\"winningPlan\", Document.class);\n",
177+
"\n",
178+
"var inputStage = winningPlan.get(\"inputStage\", Document.class);\n",
179+
"var usesIndex = winningPlan.toJson().contains(\"IXSCAN\");\n",
180+
"\n",
174181
"System.out.println(\"Execution time (ms): \" +\n",
175182
" explainResult.get(\"executionStats\", Document.class).get(\"executionTimeMillis\"));\n",
176183
"\n",
177-
"System.out.println(\"Index usage: \" +\n",
178-
" explainResult.get(\"queryPlanner\", Document.class)\n",
179-
" .get(\"winningPlan\", Document.class)\n",
180-
" .toJson()\n",
181-
" .contains(\"IXSCAN\"));"
184+
"System.out.println(\"Index usage: \" + usesIndex);\n",
185+
"\n",
186+
"if (inputStage != null && inputStage.getString(\"indexName\") != null) {\n",
187+
" System.out.println(\"Index name: \" + inputStage.getString(\"indexName\"));\n",
188+
"}"
182189
]
183190
},
184191
{

0 commit comments

Comments
 (0)