Docs / Outputs / MongoDB

MongoDB

Store the entries in a MongoDB collection through a Doctrine ODM document manager.

Overview

PackageReadsPurgeSetup
doctrine/mongodb-odm-bundleYesYesYes

The commands, the EasyAdmin viewer and ReaderInterface can read this output. audit-log:purge and audit-log:setup work with it. See Outputs.

Enable the output

config/packages/symfonycorp_audit_log.yaml
symfonycorp_audit_log:
    outputs:
        mongodb:
            document_manager: ~           # null = the default one
            collection: audit_log

Create the collection

The output does not create its collection by default. Without it, a write can fail, and the bundle only logs the failure. Run the setup command when you deploy:

terminal
$ bin/console audit-log:setup --output=mongodb

The command creates the indexes on id (unique), occurredAt, (source, occurredAt), (action, occurredAt) and each key of indexed_context.

In development and in tests, you can set auto_setup: true to create the collection on the first write. Do not use it in production.

Indexed context - when you change indexed_context, run audit-log:setup before you deploy. It creates the missing indexes. See the context filter.