Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I view the execution plan of a mongoose.js query

I want to verify that the mongoose query that I'm creating is using my indexes. Is there a way that I can view the final query that is generated to mongodb so that I can run a .explain() on the query?

I can guess what the query it is generating is, but just wanted to verify.

e.g.

 var query = Post.find()
   .regex('lowerCaseTitle', searchRegEx)
   .$gte('status',0)
   .$lt('start', now)
   .$gt('end',now)
   .sort('total', -1)
   .limit(50);
like image 649
MonkeyBonkey Avatar asked Mar 28 '12 15:03

MonkeyBonkey


1 Answers

You can get the execution query using the debug option on mongoose:

mongoose.set('debug', true);

or

mongoose.set('debug', function (collectionName, method, query, doc, options) {
  //
});
like image 108
maxcnunes Avatar answered Sep 21 '22 15:09

maxcnunes