Using Liquibase with MongoDB in Docker and Atlas



Using Liquibase with MongoDB in Docker and Atlas

Using Liquibase with MongoDB in Docker and Atlas

Founded in 2009, Mongo is the most widely used NoSQL database. Built to be a schemaless document store, MongoDB easily persists JSON objects and is considered a developer friendly database. Unlike a relational database which requires you to create your schema first, MongoDB will use any document structure the application sends.

However, this creates challenges with administering MongoDB. Because of these challenges, MasterCard chose Liquibase as a platform for their MongoDB change solution. By open sourcing their Liquibase contributions, all MongoDB users can benefit.

The entire Liquibase community is beyond grateful to MasterCard for not only identifying these challenges, but also solving them and sharing. This is proof of the power of open source.

In this video, I will show you how Liquibase can create new collections, documents, and indexes in MongoDB. I will then show you how Liquibase can support MongoDB regardless of where it is running. The two examples I will use today are MongoDB in a Docker container and in Atlas, MongoDB’s cloud offering.

MongoDB Liquibase Extension: https://docs.liquibase.com/start/install/tutorials/mongodb.html
MongoDB Liquibase Documentation: https://docs.liquibase.com/start/install/tutorials/mongodb.html
MongoDB Liquibase Changelog Example: https://gist.github.com/r2liquibase/6dbda0a31a83d3bf5e488d7d6f672e45

MongoDB Liquibase.properties (local Docker):
url: mongodb://localhost:27017/liquibase
changelog-file: changelog.xml
liquibase.hub.mode=off

MongoDB Liquibase.properties (Atlas):
url: mongodb+srv://<user>:<password>@<server>/<database>?retryWrites=true&w=majority
changelog-file: changelog.xml
liquibase.hub.mode=off

(Can be located in Atlas: Deployment &gt Database &gt Connect &gt Connect your application &gt Select Java with 3.7 or later)

Thank you to Luc Perkins, Jim Wilson, and Eric Redmond for the MongoDB examples I used. I highly recommend their wonderful book “Seven Databases in Seven Weeks” for a wonderful database survey. This book will familiarize you the deeper differences between database types very quickly: https://pragprog.com/titles/pwrdata/seven-databases-in-seven-weeks-second-edition/

For the security minded, I changed the password after the video was recorded. Also, Atlas is locked down to my IP address.

Thanks!
Robert

Comments are closed.