FlyWay CLI - MongoDB support
Which version and edition of Flyway are you using?
Flyway Open Source on Docker - image:flyway/flyway:10.15.0-alpine
Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)
CLI
Which database are you using? (Type & version)
Mongo DB 7.0.11
Which operating system are you using?
Mac OS host system
What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)
flyway -environment="mongodb" -url="jdbc:mongodb://***/***" -user=*** -password=*** -locations="filesystem:/path/to/migration/directory" -sqlMigrationSuffixes=.js info
What did you expect to see?
Info of migration to actually be produced.
What did you see instead?
ERROR: No database found to handle jdbc:mongodb://***/***
I'm aware Redgate documentation (https://documentation.red-gate.com/fd/mongodb-225608320.html) states that MongoDB CLI support is available in Redgate Distribution only while in preview. I was wondering if we have any date or estimated time for the mongo db support to exit the preview status and be finally able to manage migrations on MongoDB. I know that Redgate Community edition is able to manage MongoDB in the CLI but I'd like to stick with the Open Source version.
Thanks in advance for any information you can provide :)
Thank you for your issue. Currently, there is no date set for Mongo support to come out of preview. We are still accessing the driver we are currently requiring for this implementation for MongoDB.
We are working on potential alternatives but we have yet to define an estimate for that assessment to be over.
In the meanwhile, we are only not packaging MongoDB support in Flyway Command-line. An open source jar of the MongoDB integration is available on Maven Central. By adding this JAR and the driver specified in the Redgate documentation (https://documentation.red-gate.com/fd/mongodb-225608320.html) to your Flyway Command-line within the lib/flyway and drivers directories respectively. This will allow the command-line to access this integration.
Hi Barry, thanks a lot for your reply. I followed your indications, but I think I'm still missing something.
I uploaded the Open Source JAR from maven central in lib/flyway as reported below:
I then uploaded the JetBrains' driver in drivers as reported below:
And then tried to execute flyway -environment="mongodb" -url="jdbc:mongodb://***/***" -user=*** -password=*** -locations="filesystem:/path/to/migration/directory" -sqlMigrationSuffixes=.js info but still getting the ERROR: No database found to handle jdbc:mongodb://***/*** error.
I tried to specify explicitly the driver using the option -driver=com.dbschema.MongoJdbcDriver but that didn't work either.
Can you help me? I don't know if I'm still missing something.
Thanks a lot in advance.
Hi @fmarino-412, I saw that you are using the mongo-jdbc-standalone-1.18.jar.
After inspecting the pom inside flyway-database-mongodb:10.15.0, I realized that the Flyway community edition is now pointing to some Jetbrains DataGrip Github repo:
<dependency> <groupId>com.github.kornilova203</groupId> <artifactId>mongo-jdbc-driver</artifactId> <version>1.19</version> </dependency>
which can be checkout here: mongo-jdbc-driver and for some reason they haven't been able to publish artifact to Maven Central.
I found a Flyway write-up using that same link here: Flyway MongoDB
I then proceeded to build that standalone artifact (shadowJar) on my localhost and got: mongo-jdbc-standalone-1.19.jar, which I then published to my local repo (if you know Gradle you can do this from within the buildscript block).
NOTICE: the version number was bumped.
However, me too, am dealing with the same problem as many others:
Caused by: org.flywaydb.core.api.FlywayException: No database found to handle jdbc://mongodb://localhost:27017/mydb?authSource=admin at org.flywaydb.core.internal.jdbc.DriverDataSource.<init>(DriverDataSource.java:158) at org.flywaydb.core.internal.jdbc.DriverDataSource.<init>(DriverDataSource.java:96) at org.flywaydb.core.api.configuration.ClassicConfiguration.setDataSource(ClassicConfiguration.java:1109) at org.flywaydb.core.api.configuration.FluentConfiguration.dataSource(FluentConfiguration.java:631) at com.dictarize.health.dicdoc.config.FlywayConfig.flyway(FlywayConfig.java:25) at com.dictarize.health.dicdoc.config.FlywayConfig$$SpringCGLIB$$0.CGLIB$flyway$0(<generated>) at com.dictarize.health.dicdoc.config.FlywayConfig$$SpringCGLIB$$FastClass$$1.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:348) at com.dictarize.health.dicdoc.config.FlywayConfig$$SpringCGLIB$$0.flyway(<generated>) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) ... 23 common frames omitted
BTW: After Switzerland (my home country) beat Italy at the Eurocup today, I can only say: Forza Svizzera!
I am very naive, but why is some 3rd party mongodb-jdbc is being used instead of
https://github.com/mongodb/mongo-jdbc-driver aka https://central.sonatype.com/artifact/org.mongodb/mongodb-jdbc?smo=true
as in
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-jdbc</artifactId>
<version>2.2.0</version>
</dependency>
From what appears to be mongodb upstream?
Just following up - does this ticket still need attention, or is there something missing even after following the posted guide here https://documentation.red-gate.com/fd/mongodb-225608320.html
I have the same issue describe above "ERROR: No database found to handle" on Gitlab CI/CD with TOML conf file
Just following up - does this ticket still need attention, or is there something missing even after following the posted guide here https://documentation.red-gate.com/fd/mongodb-225608320.html
Last I tried I still had the No database found to handle error even with following your documented process. So yes, it's still an issue,
I am very naive, but why is some 3rd party mongodb-jdbc is being used instead of
https://github.com/mongodb/mongo-jdbc-driver aka https://central.sonatype.com/artifact/org.mongodb/mongodb-jdbc?smo=true
as in
<dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-jdbc</artifactId> <version>2.2.0</version> </dependency>From what appears to be mongodb upstream?
I'm not 100% on this, but it looks like mongodb-jdbc is for use with the MongoDB Atlas SQL interface - you would use it if you want to write SQL queries against your MongoDB cluster. Flyway, on the other hand, needs to run MQL queries, but it is also coupled to JDBC, so it needs a "special" driver that functions like both a JDBC driver and a regular MongoDB driver. That's what the DataGrip driver provides.
If Flyway can be decoupled from JDBC, then it could simply use the default MongoDB driver that Mongo themselves provide.
See this issue: https://github.com/flyway/flyway/issues/3546
Can anyone confirm if this is what's happening?
For anyone trying to get flyway-database-mongodb working in a Spring Boot app (alongside spring-data-mongodb), here is a setup I got to work.
Snippet from pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.12</version>
<relativePath/>
</parent>
<groupId>com.example.demo</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>demo</description>
<properties>
<flyway.version>10.21.0</flyway.version>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Dependencies needed for Flyway migrations -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>
<!-- This dependency is in preview, so future versions may include breaking changes.
See https://documentation.red-gate.com/flyway/flyway-cli-and-api/supported-databases/mongodb -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-mongodb</artifactId>
<version>${flyway.version}</version>
<exclusions>
<!-- Exclude this so it can be manually included from local jar -->
<exclusion>
<groupId>com.github.kornilova203</groupId>
<artifactId>mongo-jdbc-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- We have to manually include this jar, since Flyway uses a JDBC driver, even though it's MongoDB. -->
<dependency>
<groupId>com.github.kornilova203</groupId>
<artifactId>mongo-jdbc-driver</artifactId>
<version>1.19</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/mongo-jdbc-standalone-1.19.jar</systemPath>
</dependency>
<!-- This is necessary because Flyway uses a JDBC driver, even though it's MongoDB.
Without this, the Flyway initializer bean doesn't get created. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
</dependencies>
Snippet from application.yml:
spring:
application:
name: demo
data:
mongodb:
uri: mongodb://localhost:27017
database: demo
datasource:
url: jdbc:${spring.data.mongodb.uri}/${spring.data.mongodb.database}
driver-class-name: com.dbschema.MongoJdbcDriver
flyway:
url: ${spring.datasource.url}
driver-class-name: ${spring.datasource.driver-class-name}
baseline-on-migrate: true
sql-migration-suffixes: .js
Hi Barry, thanks to your solution, I was able to add the support for MongoDB. But my question, any news about when this can be in a stable version? If not anytime soon, where can I find the reported issue to this feature?
Hi @fmarino-412 ,
Flyway now has a new release 11.1.0 which utilizes native connectors for MongoDB and enabled in OSS edition. For more information please refer to https://documentation.red-gate.com/flyway/flyway-cli-and-api/tutorials/tutorial-using-native-connectors-to-connect-to-mongodb.
This is a new preview feature, and we greatly welcome any feedback you may have. I will close this ticket for now, but please feel free to raise new tickets to share your feedback or report any issues you encounter.
that's a great news to hear ! thx