Skip to main content

MongoDB Audit Store

The MongoDB audit store (MongoDBSyncAuditStore) enables Flamingock to record execution history and ensure safe coordination across distributed deployments using MongoDB as the storage backend.

For a conceptual explanation of the audit store vs target systems, see Audit store vs target system.

Version Compatibility

ComponentVersion Requirement
MongoDB Java Driver4.0.0+

MongoDB 4.0+ is recommended for optimal performance and feature support.

Installation

Add the MongoDB Java sync driver dependency to your project:

implementation("org.mongodb:mongodb-driver-sync:5.2.0")

Basic setup

Configure the audit store:

var auditStore = new MongoDBSyncAuditStore(mongoClient, mongoDatabase);

The constructor requires the MongoDB client and database. Optional configurations can be added via .withXXX() methods.

Register Audit Store

Once created, you need to register this audit store with Flamingock. See Registering the community audit store for details.

Audit Store Configuration

The MongoDB audit store uses explicit configuration with no global context fallback.

Constructor Dependencies (Mandatory)

These dependencies must be provided at audit store creation time with no global context fallback:

DependencyConstructor ParameterDescription
MongoClientmongoClientMongoDB connection client - required for audit store configuration
MongoDatabasemongoDatabaseTarget database instance - required for storing audit data

Optional Configuration (.withXXX() methods)

These configurations can be customized via .withXXX() methods with no global context fallback:

ConfigurationMethodDefaultDescription
WriteConcern.withWriteConcern(concern)MAJORITY with journalWrite acknowledgment level
ReadConcern.withReadConcern(concern)MAJORITYRead isolation level
ReadPreference.withReadPreference(pref)PRIMARYServer selection for reads
Audit Repository Name.withAuditRepositoryName(name)flamingockAuditLogCollection name for audit entries
Lock Repository Name.withLockRepositoryName(name)flamingockLockCollection name for distributed locks

Important: These default values are optimized for maximum consistency and should ideally be left unchanged. Override them only for testing purposes or exceptional cases.

Configuration example

Here's a comprehensive example showing the configuration:

// Audit store configuration (mandatory via constructor)
var auditStore = new MongoDBSyncAuditStore(mongoClient, auditDatabase)
.withWriteConcern(WriteConcern.W1) // Optional configuration
.withReadPreference(ReadPreference.secondary()); // Optional configuration

// Register with Flamingock
Flamingock.builder()
.setAuditStore(auditStore)
.addTargetSystems(targetSystems...)
.build();

Audit store configuration resolution:

  • MongoClient: Must be provided via constructor
  • MongoDatabase: Must be provided via constructor
  • WriteConcern: Uses explicit configuration instead of default
  • ReadPreference: Uses explicit configuration instead of default

This architecture ensures explicit audit store configuration with no fallback dependencies.

Next steps