Liquibabse command failure when mongo jars are present on classpath

Hi Guys,

My liquibase commands for oracle database are failing when mongo-driver and liquibase-extension jars are present on the LIQUIBASE_HOME/lib folder. They run fine if I remove mongo related jars.

Could please look into this and suggest the resoulution.

Thanks.

1 Like

Hi @Ashwani_Pratap,

To better diagnose could you provide some more info:

  • What version of liquibase are you using?
  • What is the exact command you are running (ex. liquibase update)
  • complete error log (not just snippet, please set logLevel=DEBUG in your liquibase.properties file or at the commandline)

Thanks!

Hi @rakhi,

  • I am using Liquibase 4.3.1 version.

  • Below jars were present on my LIQUIBASE_HOME/lib folder while running it for Oracle database.
    liquibase-mongodb-4.3.1.jar
    mongo-java-driver-3.9.1.jar
    ojdbc8-12.2.0.1.0.jar

  • I ran the following command. I ran it without classpath and driver as well and got the same output.
    liquibase --driver=oracle.jdbc.driver.OracleDriver --classpath=C:\apps\liquibase-4.3.1\lib\ojdbc8-12.2.0.1.0.jar --url=jdbc:oracle:thin:@blrdev000330.bpc.broadcom.net:1521:EE --username=system --password=oracle --logLevel=debug history

  • Please find below debug logs.
    [2021-04-01 12:33:02] FINE [liquibase.servicelocator] Loaded liquibase.license.LicenseService instance liquibase.pro.license.keymgr.DaticalTrueLicenseService
    [2021-04-01 12:33:02] INFO [liquibase.integration] No Liquibase Pro license key supplied. Please set liquibaseProLicenseKey on command line or in liquibase.properties to use Liquibase Pro features.
    Liquibase Community 4.3.1 by Datical
    ####################################################

_ _ _ _

| | () () |

| | _ __ _ _ _ | |_ __ _ ___ ___

| | | |/ _ | | | | | '_ \ / _ / __|/ _ \

| || | (| | || | | |) | (| _ \ __/

_/|_, |_,||./ _,|/__|

| |

|_|

Get documentation at docs.liquibase.com

Get certified courses at learn.liquibase.com

Free schema change activity reports at

https://hub.liquibase.com

####################################################
Starting Liquibase at 12:33:02 (version 4.3.1 #26 built at 2021-02-12 17:41+0000)
[2021-04-01 12:33:02] FINE [liquibase.integration] Liquibase Hub URL: https://hub.liquibase.com
[2021-04-01 12:33:02] FINE [liquibase.integration] Liquibase Hub Mode: all
[2021-04-01 12:33:02] FINE [liquibase.resource] Adding path C:\Users\ashwanipratap. to resourceAccessor liquibase.resource.FileSystemResourceAccessor
[2021-04-01 12:33:02] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.CockroachDatabase
[2021-04-01 12:33:02] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.DB2Database
[2021-04-01 12:33:02] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.Db2zDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.DerbyDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.Firebird3Database
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.FirebirdDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.H2Database
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.HsqlDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.InformixDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.Ingres9Database
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.MSSQLDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.MariaDBDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.MockDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.MySQLDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.OracleDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.PostgresDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.SQLiteDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.SybaseASADatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.SybaseDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.database.core.UnsupportedDatabase
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.ext.mongodb.database.MongoLiquibaseDatabase
[2021-04-01 12:33:03] FINE [liquibase.database] Properties:
[2021-04-01 12:33:03] FINE [liquibase.database] Key:‘user’ Value:‘system’
[2021-04-01 12:33:03] FINE [liquibase.database] Key:‘password’ Value:’**********’
[2021-04-01 12:33:03] FINE [liquibase.database] Connecting to the URL:‘jdbc:oracle:thin:@blrdev000330.bpc.broadcom.net:1521:EE’ using driver:‘oracle.jdbc.driver.OracleDriver’
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.DatabaseConnection instance liquibase.database.jvm.JdbcConnection
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.DatabaseConnection instance com.datical.liquibase.ext.database.jvm.ProJdbcConnection
[2021-04-01 12:33:03] FINE [liquibase.servicelocator] Loaded liquibase.database.DatabaseConnection instance liquibase.ext.mongodb.database.MongoConnection
Unexpected error running Liquibase: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Could not open connection to database: UNKNOWN
For more information, please use the --logLevel flag
[2021-04-01 12:33:03] SEVERE [liquibase.integration] Unexpected error running Liquibase: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Could not open connection to database: UNKNOWN
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Could not open connection to database: UNKNOWN
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:131)
at liquibase.integration.commandline.Main.doMigration(Main.java:1412)
at liquibase.integration.commandline.Main$1.lambda$run$0(Main.java:364)
at liquibase.Scope.lambda$child$0(Scope.java:160)
at liquibase.Scope.child(Scope.java:169)
at liquibase.Scope.child(Scope.java:159)
at liquibase.Scope.child(Scope.java:138)
at liquibase.integration.commandline.Main$1.run(Main.java:363)
at liquibase.integration.commandline.Main$1.run(Main.java:193)
at liquibase.Scope.child(Scope.java:169)
at liquibase.Scope.child(Scope.java:145)
at liquibase.integration.commandline.Main.run(Main.java:193)
at liquibase.integration.commandline.Main.main(Main.java:156)
Caused by: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Could not open connection to database: UNKNOWN
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:217)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:176)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:141)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:96)
… 12 more
Caused by: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Could not open connection to database: UNKNOWN
at liquibase.database.ConnectionServiceFactory.create(ConnectionServiceFactory.java:36)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:214)
… 15 more
Caused by: liquibase.exception.DatabaseException: Could not open connection to database: UNKNOWN
at liquibase.ext.mongodb.database.MongoConnection.open(MongoConnection.java:104)
at liquibase.database.ConnectionServiceFactory.create(ConnectionServiceFactory.java:33)
… 16 more
Caused by: java.lang.IllegalArgumentException: The connection string contains invalid user information. If the username or password contains a colon (:slight_smile: or an at-sign (@) then it must be urlencoded
at com.mongodb.ConnectionString.(ConnectionString.java:309)
at liquibase.ext.mongodb.database.MongoConnection.open(MongoConnection.java:96)
… 17 more

Hey @Ashwani_Pratap ,

I’m not very sure, but from the logs you provided it’s clear it has something to do with the connection URL.

Could you check the URL if it’s correct?

What I think is after the port number, we should be having database name in the URL separated with a / like this:

–url=jdbc:oracle:thin:@blrdev000330.bpc.broadcom.net:1521/DBNAME

Now talking about the logs, if you are trying to connect to Oracle database I’m curious about how MongoDB logs/exception logs are coming in picture :thinking:
Could you please check on this point once?

Talking about the exception message :
The connection string contains invalid user information. If the username or password contains a colon (:) or an at-sign (@) then it must be urlencoded

This exception is thrown when we try connecting to MongoDB database and the connection string or the username or the password contains : or @. In such a case, it’s a good practice to encode these values and then use them.
This could be the last thing to try out once. :slight_smile:

I hope something out from the above mentioned points works out. :slight_smile:

Rakhi Agrawal

Hi Rakhi,

We managed to run this command when the MongoDB driver is not in the lib folder.

It looks like liquibase is picking the wrong driver.

The scenario is like the following:
place the oracle and the MongoDB driver inside the lib folder and try to execute aginst oracle.

Thanks,
Yochay.

Hi @YochayMe ,

Sorry I got the question wrong earlier. Thanks for the clear explanation it’s clear now.

Would you mind trying out with some newer or older version (I would suggest to try with both to have clear idea) of Liquibase once? It could be the case of bug in specific version only. This will give us a confirmation to help improvise liquibase.

Thanks!

Rakhi Agrawal

Hi @rakhi,

We have tried with the following versions of Liquibase and liquibase-mongodb extension jars. We have received the same error in all cases.

v4.3.2
v4.3.1
v4.3.0
v4.2.2

Thanks!
Ashwani

@Ashwani_Pratap this sounds like a bug. Would you mind logging in a ticket here?

You might get suggestions on the issue or if it’s really a bug then it might help improvising Liquibase. :slight_smile:

Thanks!

Rakhi Agrawal

Hi Rakhi,

Following your suggestion, I raised the below issue. Please let me know if you get anything in meantime.

Thanks!
Ashwani

1 Like

There is a similar one on Mongo Extension repo as well:

1 Like

Hi @alexandru.slobodcico

Thank you for your prompt response.

We understand that there is a internal Executor which you had to implement and inject with priority.
Have you raised this issue with liquibase to map MongoExecutor(NoSqlExecutor) to LiquibaseMongoDatabase only.

The above Liquibase CLI is explicitly specifying the Oracle driver ( --driver ) and explicitly specifying the Oracle ojdbc jar ( --classpath ):

–driver=oracle.jdbc.driver.OracleDriver --classpath=C:\apps\liquibase-4.3.1\lib\ojdbc8-12.2.0.1.0.jar

So in this case, the user has explicitly provided which driver and which classpath should be used. In this case, Liquibase doesn’t need to guess/figure out which configuration should be used - as it is explicitly specified by the command line arguments.

Should we use a different folder ( other than lib ) for storing all the required drivers?
We would like to have a single folder location for storing all required drivers - so users can easily extend the Liquibase integration (by adding more drivers to this folder) without any need to update the integration source code.

Having a single location for all drivers is working fine with all other drivers except for MongoDB driver.
Once the MongoDB driver is present at the lib folder - Liquibase is picking it although the specified driver and classpath are specifying Oracle.

This is a blocker issue.

Kind regards
Ofer

Hi @ofer.yaniv even if specified --driver=oracle.jdbc.driver.OracleDriver, looks it get confused on the Liquibase DatabaseConnection implementation it has to use.
Executor is the next thing I suppose has to fail after the DatabaseConnection priority fixed.

For now yes the single option is to have separate folder to be used with Mongo. Indeed the target is to be able to combine any.
Yes, it was communicated to liquibase and the issue raised by @Ashwani_Pratap will properly cover that.

1 Like

Hi @alexandru.slobodcico

Thank you for the update.

At Liquibase team request - we have filed a bug Liquibabse commands are failing for other databases when mongodb jars are also present on classpath ¡ Issue #1782 ¡ liquibase/liquibase ¡ GitHub

Not only the CLI explicitly includes the driver - the CLI also explicitly include the jar classpath ( ojdbc8-12.2.0.1.0.jar - which is ignored ).

We would wait for the analysis of Liquibase team on this bug.

Thanks
Ofer

Thanks! @Ashwani_Pratap

This will help us improvize liquibase. Will let you know if I get anything on this in the meantime.

1 Like

Thank you @rakhi for the update.

Could you please try to reproduce the issue and confirm that you are indeed experiencing the same?

We would like to know whether we are missing something at the CLI execution or not.
When we remove the mongodb jar file from the lib folder - the exact same CLI command is running successfully.

Thanks
Ofer

I experienced the same issue when I had the Mondodb jar in my lib folder. Liquibase 3.10.2.

1 Like

Opened PR on liquibase, after merged and released will be able to fix liquibase-mongodb: