[CXX-1819] No explain option on find/cursor Created: 14/Sep/19  Updated: 30/Jan/20  Resolved: 30/Jan/20

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: 3.4.0
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Pieter Jordaan Assignee: Kevin Albertson
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Currently, there is no way to get the explain output for finds or cursors for that matter. 



 Comments   
Comment by Kevin Albertson [ 30/Jan/20 ]

Hi pieterwjordaanpc@gmail.com,

The drivers CRUD specification no longer specifies that drivers accept generic modifiers (like $explain) as part of the options to find. That is why the mongocxx::options::find class does not have it available. The Q&A in the CRUD spec explains the rationale:

Q: What about explain?
Explain has been determined to be not a normal use-case for a driver. We'd like users to use the shell for this purpose. However, explain is still possible from a driver. For find, it can be passed as a modifier. Aggregate can be run using a runCommand method passing the explain option. In addition, server 3.0 offers an explain command that can be run using a runCommand method.

If you are using a MongoDB server >= 3.0, you can use mongocxx::database::run_command to pass the explain command:
https://docs.mongodb.com/manual/reference/command/explain/

Best,
Kevin

Generated at Wed Feb 07 22:04:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.