Why do you need to log queries?
- In case you want to know how long it takes to execute a specific query.
- To see which is the slowest query.
- If you want to see which queries are actually being run (in case you're using a layer of abstraction like Morphia this can be a pretty interesting question)
- ...
Using MongoDB's built in profiling tool it's very simple to achieve this:
- You can enable and disable profiling on a per database level (being disabled by default).
- Connect to the database on the shell / CMD (assuming you're using the port 8082): mongo localhost:8082/erpel_test
- Activate profiling for all queries, not just slow ones: db.setProfilingLevel(2);
- Exit the shell / CMD and run some queries.
- Your database should now have a new collection called system.profile, showing the raw queries and how long it took to execute them.
For additional profiling options see
http://www.mongodb.org/display/DOCS/Database+Profiler.
Also check this out: http://www.lennartkoopmann.net/post/3603788835/mongo-analyzer
ReplyDelete