Copacetic

Ace King, check it out!

Posts Tagged ‘Atlas

Connecting to MongoDB Atlas

leave a comment »

Atlas is the MongoDB database as a service offering. With Atlas, you can create fully managed MongoDB databases on AWS, Google Cloud, and Azure. If you have been playing around with MongoDB locally you will know how trivially easy it is for clients and servers to connect.

Servers listen by default on port 27017 and clients by default expect to connect to localhost:27017. With Atlas, we need to connect to a remote server that expects both a username and password and an SSL connection.  But don’t worry Atlas makes this super easy to configure.

First login to your Atlas cluster at cloud.mongodb.com. Here is my login page.

Screen Shot 2018-03-22 at 09.49.15

Now click the connect button. This will pop up the following screen.

Screen Shot 2018-03-22 at 09.49.31

You want to scroll down to the Connect Your Application and click there.

This will open up the Connection string screen.

Screen Shot 2018-03-22 at 09.49.46

You now need to decide whether you are using the latest drivers (3.6) or an earlier version. When you originally created the cluster you selected a specific version of the server on the Create cluster page.

Screen Shot 2018-03-22 at 10.18.26

If you are using a 3.6 driver then the server will be configured to use the new seedlist configuration format.

If you click on that link you will get a window displaying the correct connection string.

Screen Shot 2018-03-22 at 09.50.01.png

This string is hard to read on the screenshot so we can reproduce it here.

mongodb+srv://jdrumgoole:<PASSWORD>@mugalyser-ffp4c.mongodb.net/test

Screen Shot 2018-03-22 at 09.50.06

For the 3.4 and earlier drivers, we use the old format MongoDB URI connection string.

mongodb://jdrumgoole:<PASSWORD>@mugalyser-shard-00-00-ffp4c.mongodb.net:27017,mugalyser-shard-00-01-ffp4c.mongodb.net:27017,mugalyser-shard-00-02-ffp4c.mongodb.net:27017/test?ssl=true&replicaSet=MUGAlyser-shard-0&authSource=admin

 

In both cases, you will need to supply the password that you created for your user. Note this is the password for the database, not your Atlas login password.

Written by Joe

March 22, 2018 at 10:30 am

Posted in joedrumgoole

Tagged with , , ,