The explain command does not fully support the maxTimeMS option due to the two following issues.
The first is that the explain shell helpers generate an explain command with the maxTimeMS parameter in the wrong location. The shell command
db.c.find().maxTimeMS(100).explain("executionStats");
generates the command:
{ explain: { find: "c", filter: {}, maxTimeMS: 100.0 }, verbosity: "executionStats" }
Instead it should place maxTimeMS as a top-level parameter:
{ explain: { find: "c", filter: {} }, verbosity: "executionStats", maxTimeMS: 100.0 }
The second issue is that mongos strips out the maxTimeMS before forwarding it to the shards. I can reproduce by starting a one-shard cluster and running the following against the mongos:
db.c.drop() for (var i = 0; i < 10; i++) { db.c.insert({_id: i}); } db.runCommand({explain: {find: "c", filter: {$where: "sleep(100)"}}, verbosity: "executionStats", maxTimeMS: 1});
When I run this directly against a mongod, it results in ErrorCodes::ExceededTimeLimit. But it does not time out when I run it against a mongos.
- is related to
-
SERVER-46686 Explain does not respect maxTimeMS
- Closed