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
generates the command:
Instead it should place maxTimeMS as a top-level parameter:
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:
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.