Unable to connect to MongoDB Atlas Cluster from Mongosh terminal - mongodb

I am trying to connect to the Mongo Atlas Cluster through the Mongosh terminal using mongosh "mongodb+srv://cluster0.sdwcf.mongodb.net/myFirstDatabase" --username <username>. But I am unable to connect the error being Error: queryTxt ETIMEOUT cluster0.sdwcf.mongodb.net. I found the same issue at https://github.com/metabase/metabase/issues/9867 but issue has been closed without any solution.
One the other hand if I try to connect using the mongo 3.4 or earlier command mongo "mongodb://cluster0-shard-00-00.sdwcf.mongodb.net:27017,cluster0-shard-00-01.sdwcf.mongodb.net:27017,cluster0-shard-00-02.sdwcf.mongodb.net:27017/myFirstDatabase?replicaSet=atlas-10n7hz-shard-0" --ssl --authenticationDatabase admin --username <username> --password <password> it works just fine. But given that the Mongosh terminal has superseded the Mongo terminal, I would really like to know if there is any fix for this..

Related

error in connection mongodb atlas to shell

mongo "mongodb+srv://sandbox-hoj54.mongodb.net/test" --authenticationDatabase admin --username m001-student --password m001-mongodb-basics
2020-06-19T14:18:02.553+0530 E QUERY [js] uncaught exception: SyntaxError: unexpected token: string literal :
#(shell):1:6
I think the problem is that you are running this command:
mongo "mongodb+srv://cluster0-jxrfu.mongodb.net/<dbname>" --username <password> on the MongoDB shell you downloaded in your <your mongo shell's download directory>/bin directory.
Instead, Open up a new command line and run the command. It worked for me.
There are two options to connect to db. Connect with the mongo shell or connect your application. It seems that you are trying to connect by the shell. You can see your connection string in the window:
MongoDB Atlas Panel > Clusters > 'Connect' button.
Of course you have to replace <dbname> and <password> as in the description.

Format for MONGO_URL when connecting MongoDB Atlas to Galaxy

Revising this question following more attempts:
I'm deploying a Meteor app on Galaxy for the first time and cannot connect to MongoDB Atlas.
I can connect to MongoDb through Mongo Shell using:
mongo "mongodb://host1:27017,host2:27017,host3:27017/<db_name>?replicaSet=<replica_set_name>" --ssl --authenticationDatabase admin --username <username> --password <password>
I tried an equivalent for the Mongo URL in my settings.json:
mongodb://<username>:<password>#host1:27017,host2:27017,host3:27017/<db_name>?authSource=admin&replicaSet=<replace_set_name>
But when I deploy my app, I get:
Error: Could not locate any valid servers in initial seed list.
I've also tried using the connection string provided by Atlas:
mongodb+srv://<username>:<password>#<host>/<db_name>?retryWrites=true&w=majority
But this just returns:
Error: URL must be in the format mongodb://user:pass#host:port/dbname
I've tried every combination I can come up with but no luck.
RESOLVED, WITH HELP FROM MONGODB ATLAS SUPPORT:
"MONGO_URL": "mongodb://:#host1:27017,host2:27017,host3:27017/?ssl=true&replicaSet=&authSource=admin&retryWrites=true&w=majority",

Programmatically connect to remote MongoDB with SSH

I need to use terminal to connect to MongoDB. I have almost precisely same issue as this StackExchange question.
In my case I can correctly use Robo3T to connect. As well as use command
mongo --host 111.111.111.111 --port 111 --authenticationDatabase DB --username USER --password PASS locally. With same command executed remotely I receive following error:
No connection could be made because the target machine actively refused it.
I wanted to precisely recreate my Robo3T connection setup to see if SSH tunnel solves my issue

Trying to run mongorestore and cannot connect?

Using MongoAtlas and trying to run mongorestore and I am getting the following error.
Failed: error connecting to db server: no reachable servers
I am using the command Atlas proposes.
mongorestore --host BStaging-shard-0/bstaging-shard-00-00-lq11i.mongodb.net:27017,bstaging-shard-00-01-lq11i.mongodb.net:27017,bstaging-shard-00-02-lq11i.mongodb.net:27017 --ssl --username heroku --password "VN" --authenticationDatabase admin
2019-04-14T11:02:31.336-0500
Failed: error connecting to db server: no reachable servers
Fixed:
Updated MongoDB community Shell
Changed bash_profile to point to new shell
Changed bash_profile to point to new mongo db community4.0
(/usr/local/opt/mongodb-community#4.0/bin:/usr/local/opt/mongodb-community-shell/bin:$PATH)
source bash_profile
reconnect to mongo
mongo "mongodb://staging-shard-00-00-dgdr.mongodb.net:27017,staging-shard-00-01-dgdr.mongodb.net:27017,staging-shard-00-02-dgdr.mongodb.net:27017/test?replicaSet=Staging-shard-0" --ssl --authenticationDatabase admin --username me --password pwd
restore
mongorestore --host Staging-shard-0/staging-shard-00-00-dgdr.mongodb.net:27017,staging-shard-00-01-dgdr.mongodb.net:27017,staging-shard-00-02-dgdr.mongodb.net:27017 --ssl --username me --password pwd --authenticationDatabase admin

How to connect to MongoDB on mLab through mongo shell?

I'm trying to connect to my database cluster on mLab through mongo shell using the commands as mentioned by the service providers but I keep getting the same error mentioning missing ";" statement. I can access the same database through mongoose client without any problem.
Any clue where I am messing up:
mongo ds117956.mlab.com:17956/image_search -u <dbuser> -p <dbpassword>
2017-11-29T03:04:33.139+0530 E QUERY [thread1] SyntaxError: missing ; before statement #(shell):1:6
you need to run from mongodb/bin
and then enter the following command: mongo ds117956.mlab.com:17956/image_search -u -p
not from mongo itself
mongo ds117956.mlab.com:17956/image_search -u -p