Log all MongoDB queries in a "tail"able way

482 views
Skip to first unread message

Mariano Ruiz

unread,
Feb 28, 2015, 2:20:36 AM2/28/15
to mongod...@googlegroups.com
Hello, I made an open source command line tool to outputs any operation from a Mongo database in the standard output. You can see the operations collected by the database profiler from a console, or redirect the result to a file, pipes it with grep or other command line tool, etc.

But the more interesting feature (also like tail) is to see the changes in "real time" with the -f option, and occasionally filter the result with grep to find a particular operation.

For example, if you want to see the logs from MYDATABASE, first you have to execute this:

    $ mongotail MYDATABASE -l 2

Then you can see the latest lines of logging with:

    $ mongotail MYDATABASE
    2015-02-24 19:17:01.194 QUERY  [Company] : {"_id": ObjectId("548b164144ae122dc430376b")}
    2015-02-24 19:17:01.195 QUERY  [User] : {"_id": ObjectId("549048806b5d3db78cf6f654")}
    2015-02-24 19:17:01.196 QUERY  [Company] : {"_id": ObjectId("548b16df44ae122dc4303771")}
    2015-02-24 19:17:10.729 COUNT  [User] : {"active": {"$exists": true}, "firstName": {"$regex": "mac"}}
    ...

Now see the changes in "real time", and filter the result with egrep to find a particular operation, like only show writes operations: mongotail databasename -f | egrep "(INSERT|UPDATE|REMOVE)"

See documentation and installation instructions in: https://github.com/mrsarm/mongotail


I hope will be usefull for you !


Stephen Steneker

unread,
Mar 1, 2015, 6:53:28 PM3/1/15
to mongod...@googlegroups.com
On Saturday, 28 February 2015 18:20:36 UTC+11, Mariano Ruiz wrote:
Hello, I made an open source command line tool to outputs any operation from a Mongo database in the standard output. You can see the operations collected by the database profiler from a console, or redirect the result to a file, pipes it with grep or other command line tool, etc.

Hi Mariano,

Thanks for sharing!

It would be great to have support for tailing the oplog rather than the system.profile collection (I added a feature suggestion on Github).

Regards,
Stephen 

Reply all
Reply to author
Forward
0 new messages