skip to content
Alvin Lucillo

Connecting to atlas db

/ 1 min read

To connect to a database, you need a database user in Database & Netwoork Access > Database Users. Using mongosh, do the one below. This is the generated mongosh command from atlas dashboard. To generate your own, go to Database > Clusters and click Connect, then choose Shell.

mongosh "mongodb+srv://cluster0.laaztrd.mongodb.net/" --apiVersion 1 --username adm1n
Enter password: ****************
Current Mongosh Log ID: 69f9e77cb15870db86544cb7
Connecting to:          mongodb+srv://<credentials>@cluster0.laaztrd.mongodb.net/?appName=mongosh+2.3.8
Using MongoDB:          8.0.21 (API Version 1)
Using Mongosh:          2.3.8
mongosh 2.8.3 is available for download: https://www.mongodb.com/try/download/shell

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

Atlas atlas-d4991z-shard-0 [primary] test>

Note: The above result is redacted

The command connects you to the cluster Cluster0. You’ll notice mongodb+srv which tells mongosh to resolve the DNS to discover the cluster hosts, instead of explicitly providing the cluster hosts. Once you’re connected, you’ll see something like Atlas atlas-d4991y-shard-0 [primary] test> , which tells you that you’re currently using test database and connected to the primary replica member.