Tips on using MongoDB Shell

Tips on using MongoDB Shell

I’m currently taking the MongoDB online course, M202 right now. It’s an advance course that covers sharded cluster, performance tuning and others useful topics. Also, I have learnt a couple of tricks about mongo shell from the course so far.

show profile

On a database that has profiling enabled, the show profile helper in the mongo shell displays the 5 most recent operations that took at least 1 millisecond to execute. Issue show profile from the mongo shell, as follows:

show profile

This is particularly useful when you don’t want to go through the entire collection. MongoDB query syntax isn’t the most intuitive language in the world and it helps when you can just do a quick analysis of the slow queries. If you need something more detailed, try this.

show log

There are many ways to view MongoDB log files:

  1. cat mongod.log
  2. via Kibana
  3. mongo shell, show log

I find that using #3 is handy, especially during a severity 1 issue. It shows all the logs that is currently in memory. This also means it will only show relevant logs 🙂

Hope this helps!

Regards,
Wei Shan

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s