MongoDB

  • Verified Versions: V5,V8
  • Maintainer: Redgate

Supported Versions and Support Levels

Terminology

We have to map Flyway concepts and language rooted in the relational database world to MongoDB - this is how Flyway sees the mapping:

MongoDB Concept Flyway Concept
database database/schema
collection table
document row
transaction transaction

Configuration

  • Flyway identifies the migration type through the file extension. You should set sqlMigrationSuffixes to .js for JavaScript migrations or .json for JSON migrations.
    • Note that Flyway doesn't support mixed migration types in a single project
  • Any non-credential configuration (see Mongo Connection String Options needs to go into the connection string (Flyway's URL parameter), as this is passed directly to both the driver and Mongosh.
    • Credentials can be provided via Flyway's standard user and password parameters
    • If you are not using the default database, you will need to include the database name and auth source in your url.
  • There is a tutorial available here.

JavaScript migrations

  • JavaScript migrations require mongosh to be installed where Flyway can use it.
  • To use JavaScript migrations with our official Docker image, you will need to use either the redgate/flyway:12.11.0-mongo, -alpine-mongo or -azure-mongo images as these include the Mongosh tool.

Limitations

  • JavaScript (.js) migrations cannot use transactions, which is a limitation of Mongosh. A warning will be displayed if executeInTransaction is set. See this blog post for more details.
  • You can't currently do a Dry-run operation with MongoDB.

This documentation contains proprietary information and is protected by copyright law.
Copyright © 2026 Red Gate Software Limited. All rights reserved


Didn't find what you were looking for?