Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i write an aggregation query with { explain : true } in mongoose

This is the code not working.

Model.aggregate([{ "$match": query }]).explain(true);

like image 788
Nesar Avatar asked Sep 15 '25 06:09

Nesar


1 Answers

Adding ,{ explain: true } after the aggregation array into a MyModel.aggregate(array, options) type of statement didn't work for me in Mongoose 5.2.7 / MongoDB 3.6.6. Luckily, MyModel.aggregate(array).explain() is now available and documented https://mongoosejs.com/docs/api.html#aggregate_Aggregate-explain

like image 168
SVUser Avatar answered Sep 17 '25 04:09

SVUser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!