Mongodb – mongodb logging as a COMMAND

mongodb

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!

Best Answer

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")