tyny.dev - the multifarious json builder | Product Hunt
TAGS

Extracting a query from MongoDB log with MongoDBLogToQuery

Another free tool, which we use on a regular basis, is our MongoDBLogToQuery parser. This tool is now available on Github under the MIT licence.

The backstory

When asked by clients to make their MongoDB setup faster, the first thing we start with is usually getting a good overview of their access patterns, which means their queries against MongoDB.

This is especially necessary on self-hosted (on-premise) MongoDB setups, not so much on setups in the cloud with MongoDB Atlas, because here we've got the query profiler, which helps identifying slow queries much faster.

In the first instance this means that we scan the MongoDB log for COLLSCAN entries. These are queries which don't use an index and therefore are very slow. After that we look for other long running queries, normally anything which takes longer than 1 second of execution time.

Keep in mind that the default MongoDB setting for logging slow queries is 100 ms, which means any query with more than 100 milliseconds of execution time is going to be logged to the MongoDB logfile.

After that we go down to anything less than 1 second and above 100 ms execution time.

At that point our MongoDBLogToQuery parser comes into play. The format MongoDB logs slow queries to the log isn't fully compatible with the JavaScript/JSON query language of MongoDB, which means you can't simply copy and paste a query from the log and execute it against the database.

There are certain things which need to be rewritten in terms for you to do that (e.g. $date to ISODate(), etc.).

How to use MongoDBLogToQuery

What our MongoDBLogToQuery parser does is that it takes one line of MongoDB log and returns an executable query, which you can paste directly into the MongoDB shell.

We implemented the parser into a web form for you to use straight away, go here and test it out.

Where to go from here

The MongoDBLogToQuery parser together with the MongoDB Query Analyzer makes up our suite of frequently used MongoDB tools.

Both of those tools are publicly available on our Github under the MIT licence. Feel free to use them, and don't hesitate getting back to us with suggestions on how to improve them.

Disclaimer: When working on client infrastructure make sure you know what to execute and the implications thereof. We're providing these tools as they are, and we're not responsible how you use them in any way. Both tools do not claim to be exhaustive.

Now go, and parse your MongoDB log messages.



 

This product has been added to your cart

CHECKOUT