[JAVA-2895] Atlas connection string question Created: 26/Jun/18  Updated: 27/Oct/23  Resolved: 29/Jun/18

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Max R Assignee: Ross Lawley
Resolution: Works as Designed Votes: 0
Labels: cluster, driver, issue, tier
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS Windows 10
MongoDB shell version v3.6.5
MongoDB server version: 3.6.5


Attachments: PNG File 100.png     PNG File 101.png    

 Description   

I've created Atlas M0 (Free Tier) cluster. (screen)

I want to add db with info to this cluster.  When I tried to connect to tier cluster via driver3.6 or later and wrote mongodb+srv://user:<PASSWORD>@cluster0-ox90k.mongodb.net/test?retryWrites=true, I always get an error: Connection strings must start with 'mongodb://'.

Okay, I deleted the snippet +srv and wrote the same way mongodb://user:<PASSWORD>@cluster0-ox90k.mongodb.net/test?retryWrites=true and was unable to connect.

So, I finally solved it via driver 3.4 or earlier, I wrote mongodb://user:<PASSWORD>@cluster0-shard-00-00-ox90k.mongodb.net:27017,cluster0-shard-00-01-ox90k.mongodb.net:27017,cluster0-shard-00-02-ox90k.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true

Why did I solve it only via 3.4 driver?
Here's my detail question with solution too - https://stackoverflow.com/questions/50916467/how-to-connect-to-atlas-m0-free-tier-cluster-correctly-via-java-driver
https://university.mongodb.com/courses/M001/2018_June/discussion/forum/threads/5b2bf4f7be6a833aaf23e399
Same issue was probably here - http://discourse.metabase.com/t/connect-to-mongodb/3597



 Comments   
Comment by Ross Lawley [ 29/Jun/18 ]

Hi romax300@ukr.net,

Thanks for the ticket.  Connection strings starting with mongodb+srv:// are only supported when using the version 3.6+ of the Java driver. DNS resolution lookup was added in the 3.6 version of the Java driver. As such removing the +srv component of the connection string would not work / resolve to your atlas cluster.

Adding the full connection string with multiple hosts is the correct way to connect to Atlas for users of the older Java drivers. However, we would recommend upgrading the driver to the latest version (3.8) to take advantage of the DNS look up and other new MongoDB features.

For more information regarding connecting to atlas please see the driver connection example and the linked MongoDB Driver compatibility matrix.

I hope that helps,

Ross

Generated at Thu Feb 08 08:58:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.