Is there a way to run explain with runCommand? I have the following query:
db.runCommand({geoNear:"Locations", near:[50,50], spherical:true})
How can I run an explain on it? I want to get the execution time.
As far as I know, explain is a method on cursors. You, however, can enable the integrated mongodb profiler:
db.setProfilingLevel(2); // log all operations
db.setProfilingLevel(1, 50); // log all operations longer than 50msecs
This will log details like nscanned, nreturned to a capped collection called system.profile, but does not provide as much detail as an explain() call does.
In this case, however, I think it might be possible to change the runCommand to a $near-query instead? That would give you full access to explain.
I guess we can't do explain for runCommand. Some of the runCommand give you the stats automatically ( eg. distinct command : db.runCommand({distinct : 'test', key : 'a'}) )
But, you can take help of the query profiler.
db.setProfilingLevel(2)
Once you run that query, switch off the profiler, and check the system.profile collection for this query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With