0

Relating to mongodb's documentation, database commands such as count will be logged as component COMMAND. However neither db.count() nor db.runCommand({count:'mycollection'}) produces a COMMAND log entry, even if the default log level for COMMAND is raised from 0 to 1. Dropping an index, a collection or a database produces a COMMAND log entry even with the default log level 0 though.

Moreover, it seems that almost all mongodb actions can be expressed as command (even a find), as shown in mongodb's documentation, so I wonder how one could properly differentiate between QUERY which logs messages related to queries and COMMANDs.

My goal is to filter out (administrative) commands from the logs for auditing (and I don't want to use mongodb's enterprise version with auditing functionalities for this single purpose). I'm using mongodb version 4.0.5 Linux 64Bit.

Thanks for shedding light on this!

0

After setting the verbosity level for command as 1, I am able to see the following entries in the log file

2019-03-01T16:25:56.967-0800 I COMMAND [conn67] command test.icons appName: "MongoDB Shell" command: count { count: "icons", $readPreference: { mode: "secondaryPreferred" }, $db: "test" } planSummary: COUNT keysExamined:0 docsExamined:0 numYields:0 reslen:45 locks:{ Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_command 0ms

here the collection name is icons and the database is test

I used the following command to increase the verbosity level.

db.setLogLevel(1, "command")
| improve this answer | |
  • Yes, you're right, it's being logged when the log level is raised from 0 to 1. I must have overseen it due to so many acquireCountlog entries which arises when the log level is raised to 1. The log becomes rapidly polluted by so many messages. Even find operations are logged then, since it's a command under the hood which leads me to my former question, how one could properly differentiate between QUERY which logs messages related to queries and COMMANDs. – Kay Mar 4 '19 at 8:30
  • Try mlogfilter , which will help you to filter log messages – Mani Mar 4 '19 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.