Connecting and interacting with cluster using MongoDB shell

Atlas provide students with the following connection string:

mongo “mongodb+srv://sandbox.mv4hux2.mongodb.net/myFirstDatabase” --username

When I used the above format, I got an error as shown below.

C:\Windows\system32>mongo “mongodb+srv://sandbox.xxxxxxx.mongodb.net/admin” --username
‘mongo’ is not recognized as an internal or external command,
operable program or batch file.

The lecture propose the use of the follwoig command

C:\Windows\system32>mongo “mongodb+srv://username:password@sandbox.xxxxxxx.mongodb.net/admin”

this gives the same error.

Obviously, mongo is no longer available command in new version of MongoDB. When I used “Mongosh” command instead of “Mongo” I get connected to Atlas but do have any databases as show below

C:\Windows\system32>mongosh “mongodb+srv://username:password@sandbox.xxxxxxx.mongodb.net/admin”
Current Mongosh Log ID: 63462b20c3561dfb4f7df3fc
Connecting to: mongodb+srv://@sandbox.xxxxxxx.mongodb.net/admin?appName=mongosh+1.6.0
Using MongoDB: 5.0.13
Using Mongosh: 1.6.0

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

Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded.
You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js.
Atlas atlas-dpf7on-shard-0 [primary] admin>

“show dbs” does not display any results.

It seems that I can connect to my cluster, but cannot interact with it. Can anybody shed some light on this problem?

Hi @Jamie_Ibrio and welcome to the MongoDB Community forums! :wave:

Connecting to an Atlas based cluster, you should at least see the admin and local databases as these are system level databases, or you should see some sort of error. Can you please paste the results of show dbs so we can see what’s going on/

Thank you for your response. It is very much appreciated. Here are two connection strings followed by “show dbs.” Although I am connected to what appears to me Atlas (… shard-0[primary] admin), “show dbs” returns nothing.

First Approach:

C:\Windows\system32>mongosh “mongodb+srv://username:password@sandbox.xxxxxxx.mongodb.net/admin”
Current Mongosh Log ID: 634756eac851bb29c54d3811
Connecting to: mongodb+srv://@sandbox.xxxxxxx.mongodb.net/admin?appName=mongosh+1.6.0
Using MongoDB: 5.0.13
Using Mongosh: 1.6.0

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

Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded.
You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js.
Atlas atlas-dpf7on-shard-0 [primary] admin> show dbs

Atlas atlas-dpf7on-shard-0 [primary] admin>

Second Approach:

C:\Windows\system32>mongosh “mongodb+srv://sandbox.xxxxxxx.mongodb.net/admin” --apiVersion 1 --username xxxxxxxxxxxx
Enter password: *******************
Current Mongosh Log ID: 63475b8fc40e3828ccc6fa4d
Connecting to: mongodb+srv://@sandbox.xxxxxxx.mongodb.net/admin?appName=mongosh+1.6.0
Using MongoDB: 5.0.13 (API Version 1)
Using Mongosh: 1.6.0

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

Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded.
You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js.
Atlas atlas-dpf7on-shard-0 [primary] admin> show dbs

Atlas atlas-dpf7on-shard-0 [primary] admin>

What do you think?

Hi Doug,
Once again thank for your kind help. Finally, I was able to connect my atlas cluster and interact with it. I did not do anything special; I used the same script and “show dbs” worked fine. So, my previous email is irrelevant. I can view all sample databases and interact with them.

Glad things started working for you Jamie! If something similar happens in the future you might need to reach out to Atlas support to have them figure out what’s going on.

1 Like