michaelklishin / monger

Monger is an idiomatic Clojure MongoDB driver with sane defaults, batteries included, well documented, low overhead
http://clojuremongodb.info
484 stars 104 forks source link

Execution Stats in Aggregate #198

Open arichiardi opened 4 years ago

arichiardi commented 4 years ago

Hi there!

Still new to Mongo but I wanted to get the execution time of my aggregate queries and while I am using explain-aggregate function, I cannot really see the executionStats section returned from it.

My Mongo is from the 3.6.17-xenial docker image.

Is there any way to access that information?

arichiardi commented 4 years ago

I found that this article would actually work but how to chain calls in monger?

https://dzone.com/articles/mongo-aggregates-and-how-to-explain-aggregate-quer

mjrb commented 3 years ago

as the article suggests you have to run explain with the executionStats option which unfortunately doesn't seem to be supported by the java driver :'( here the api only allows AggregateOptions not any explain options. You could potentially profile your query using the MongoDB shell and then using it in your clojure application. if you really want to do it in clojure you can manually use the raw runCommand interface through java interrop but that would be a bit painful.