MongoDB Atlas connection

Hi - I am trying to follow the tutorial on mongo db at : Using Liquibase with MongoDB | Liquibase Docs
The problem is in the example, it conencts to a local mongodb deployment and I want to connect to Mongo Atlas.

In the liquibase.properties file the advise is to put - “url: mongodb://hostname:27017/myDatabase”

However, Atlas URL should be “mongodb+srv://hostname:27017/myDatabase”

Liquibase does not seem to like this, it throws an exception:

Cannot find database driver: Driver class was not specified and could not be determined from the url

Surely connecting to mongo atlas should be possible? Please guide me as to how?

Thanks

Hi @spozza,

MongoDB support is provided by Liquibase extension, which means the additional functionality for the db platform is provided by the community (and is a good candidate for being pulled into liquibase core if it aligns).

I’ve never seen MongoDB Atlas being used, and so, I would recommend logging an issue so the maintainer can give the definitive response as to support, or add it if not present:

HTH,

Ronak

Thanks that helps

I did figure this out and the solution is to just use an older style url to connect it to atlas (without the srv bit) which does the job

OMG, that’s awesome @spozza,

Favor please: Would you share the format? Is it just the TLS arg in the Url?

I am so happy you got it working!

Ronak

yeah sure. So the atlas connections have the “+SRV” syntax which first problem is that it confuses the driver auto detection

To resolve, I used a backward compatible connection string like this:

mongodb://username:password@some-cluster-shard-00-00.XXXXX.mongodb.net:27017/?ssl=true&replicaSet=some-cluster-shard-0&authSource=admin&retryWrites=true&w=majority

This successfully recognizes the driver and also makes the connection.
I checked with mongo if this format was likely to be deprecated at any stage and they said very unlikely

Maybe this will help someone else someday :slight_smile:

Cheers

3 Likes

@spozza Above mentioned way is not working for me… It is giving me an error
Unexpected error running Liquibase: liquibase.exception.DatabaseException: Could not query for long
Could you please help where i am going wring ?

@spozza , thanks for your reply.

@Nitish , welcome!

Would you share the exact liquibase command you are running? If you are using a liquibase.properties file, please share the info (esp. URL and classpath). Also will need to see your complete log, its not enough info to diagnose with just the error snippet.

Hi @spozza , have you tried the latest releases?
It was fixed under:

ah thats brilliant thanks! Will convert my connection strings back again and give it a test. Thanks very much for mentioning this

@alexandru.slobodcico just updated the latest release and this is now working great! thanks again

Hey. Try this

Liquibase - - logLevel=DEBUG update