How do I do an explain on a mongo query through meteor?

Is there a way to do this? or do I have to translate my query into something I can run in the mongo shell directly and then do the .explain() on that?

Need to do it through the mongo shell, as far as I’m aware.

1 Like

OK, thanks… considering the syntax is different sometimes, it would be nice to be able to get it inside the meteor framework…

You can do it by:
Collection.find( { $query: {'some': 'query'}, $explain: 1 } ).fetch()

Cheers :slight_smile:

3 Likes

@awatson1978

Appreciate you sharing this detail about using collection.explain() in the Meteor MongoDB shell. I was testing this query via the client console but was not working.

For those interested in setting up the Meteor MongoDB shell, all you need to do is open a new terminal window or new tab in your local meteor project and type meteor mongo

Also, if you are having issues getting an explain() query to work once you get the Meteor MongoDB shell running below is a sample explain() query:

db.collection.find({"_id": ‘AMJt8j5n4Lq2T85dQ’}).explain();

Happy Coding!