Use LDAP Authentication with Liquibase and MongoDB
Last updated: July 14, 2025
Liquibase can connect to a MongoDB database using LDAP authentication by configuring MongoDB for LDAP and including the correct authentication parameters in the connection URL.
Before you begin
Before using Liquibase with LDAP, ensure your MongoDB server is configured correctly to support LDAP authentication.
MongoDB must be set up to:
Enable LDAP for external authentication
Use the correct authenticationMechanisms, such as PLAIN
Support connections over TLS/SSL if using the PLAIN mechanism
You'll need to refer to MongoDB's official documentation for setup instructions.
Procedure
Configure your liquibase.properties
Before using the example properties file below, be sure to:
Replace your_changelog.js with the name or path to your changelog file.
Replace your_hostname, your_port, and your_db_name in the connection URL for your database.
Replace your_license_key with your Liquibase Pro license key.
Replace your_username and your_password with the username and password for authenticating with MongoDB via LDAP.
Replace /tmp/liquibase.log with your preferred output file name and path, if desired.
Example Properties file
changeLogFile=your_changelog.js
liquibase.command.url=mongodb://your_hostname:your_port/your_db_name?authMechanism=PLAIN&authSource=$external
liquibase.licenseKey=your_license_key
username=your_username
password=your_password
logLevel=info
logFile=/tmp/liquibase.log
Create a test Chanelog file
Before testing the connection, create a basic changlog file that performs a simple operation. The example changelog below creates a collection.
Be sure to save the changelog file with the same name you used for your_changelog.js in your liquibase.properties
file and set the path appropriately to find the file.
Example Changelog file
// your_changelog.js
// Liquibase formatted MongoDB changelog
// Create a new collection
db.createCollection("exampleCollection");
Test the Connection
To verify your LDAP setup is working with Liquibase:
Open a terminal and navigate to the directory where your Liquibase files are stored.
Run the following command:
liquibase update
If the connection is successful and the exampleCollection is created, your LDAP configuration is working correctly.