- Reference >
- Database Commands >
- Administration Commands >
- setAuditConfig
setAuditConfig¶
On this page
Definition¶
-
setAuditConfig¶ New in version 5.0.
setAuditConfigis an administrative command that sets new audit configurations formongodandmongosserver instances at runtime.The command syntax is:
setAuditConfighas the following fields:Field Type Description setAuditConfiginteger Run setAuditConfigfilterdocument An audit filter auditAuthorizationSuccessboolean Log all, or only failed access authorizations Use the
db.adminCommand( { command } )method to runsetAuditConfigagainst theadmindatabase.
Behavior¶
Enable Auditing to use
setAuditConfig at runtime.
auditAuthorizationSuccess enables auditing of authorization success for the authCheck action. The parameter value must be
true to audit read and write operations. However, when
auditAuthorizationSuccess is false auditing has less
performance impact because the audit system only
logs authorization failures.
Configuration updates are distributed via the oplog mechanism
which means updates on mongod nodes are distributed to
secondary nodes very quickly. There is a different distribution
mechanism on mongos nodes. mongos nodes
have to poll the primary
server at regular intervals for configuration updates. You may see
stale data due to polling delay if you run setAuditConfig
on the primary server and getAuditConfig on a
shard before the shard has polled the primary server
for updated configuration details.
Examples¶
In these examples the audit messages have been reformatted. They appear on a single line in the log file.
Audit Collection Creation and Deletion¶
Enable auditing when a collection is created or deleted.
When the inventory collection is created in the sales database,
the audit system will log a message like this:
When the inventory collection is dropped from the sales
database, the audit system will log a message like this:
Audit Document Interactions¶
Set auditAuthorizationSuccess to true and create a
filter which includes actions of interest to audit read and write
operations.
Search the inventory collection in the sales database using the
find command to create an audit log entry like this one:
See also