mongodb(): Store messages in a MongoDB database

The mongodb() driver sends messages to a MongoDB database. MongoDB is a schema-free, document-oriented database. For the list of available optional parameters, see mongodb() destination options.

Prerequisites

This feature requires a separate module. Install the axosyslog-mod-mongodb package on Debian/Ubuntu, or the axosyslog-mongodb package on RHEL and compatible distributions. If the module isn’t installed, AxoSyslog fails to start with an unexpected LL_IDENTIFIER error.

Declaration

Terminal window
   mongodb(parameters);

The mongodb() driver does not support creating indexes, as that can be a very complex operation in MongoDB. If needed, the administrator of the MongoDB database must ensure that indexes are created on the collections.

The mongodb() driver does not add the _id field to the message: the MongoDB server will do that automatically, if none is present. If you want to override this field from AxoSyslog, use the key() parameter of the value-pairs() option.

The AxoSyslog mongodb() driver is compatible with MongoDB server version 1.4 and newer.

Example: Using the mongodb() driver

The following example creates a mongodb() destination using only default values.

Terminal window
   destination d_mongodb {
        mongodb();
    };

The following example displays the default values.

Terminal window
   destination d_mongodb {
        mongodb(
            uri("mongodb://localhost:27017/syslog")
            collection("messages")
            value-pairs(
                scope("selected-macros" "nv-pairs" "sdata")
            )
        );
    };
Last modified October 2, 2026: Delete obsolete mongodb examples (ef72d65c)