mongodb how to get the correct uri - mongodb

I've inherited node.js, mongodb system.
The original dev used a mlab db on his own account, I was asked to copy to a different db.
When I tried to create a mlab user I was redirected to cloud.mongodb.com (which apparently purchase mlab)
I was struggling to create a DB and connect to it through robo 3t and Compass, and now I'm able to connect and query the DB.
I used Compass export/import collection to copy the DB (was not able to copy in any other way)
Now I set the db uri in my app to the new db but it hangs when I do findOne
here is the old uri:
mongodb://dekel:password#ds115094.mlab.com:15094/somebuddy
therefore I assumed the connection string should be:
mongodb://root:password#cluster0-shard-00-00-jjbdh.mongodb.net:27017/somebuddy
I get
UnhandledPromiseRejectionWarning: MongoNetworkError: connection 0 to cluster0-shard-00-00-jjbdh.mongodb.net:27017 closed
when I connect with robo 3t I have to set the Database to admin other wise I get: Network is unreachable.
therefore I tried the following
mongodb://root:password#cluster0-shard-00-00-jjbdh.mongodb.net:27017/admin
I get:
MongoNetworkError: connection 0 to cluster0-shard-00-00-jjbdh.mongodb.net:27017 closed
The Mongodb site says that the connection string should be
mongodb+srv://root:<password>#cluster0-shard-00-00-jjbdh.mongodb.net/test?retryWrites=true
This is very strange since cluster0-shard-00-00-jjbdh.mongodb.net doesn't work on robo 3t and Compass, so I guess it is only an example.
I tired the following
mongodb+srv://root:password#cluster0-shard-00-00-jjbdh.mongodb.net:27017/somebuddy
I get:
Error: querySrv ENOTFOUND _mongodb._tcp.cluster0-shard-00-00-jjbdh.mongodb.net
I tried with the following different users
when I tried to use the chat on the mongodb website I get:
The team will get back to you on this. MongoDB Cloud Chat will be back tomorrow.
this is what I get when i try to connect with the shell (see https://www.youtube.com/watch?v=Ej05tq1220A):
C:\Program Files\MongoDB\Server\4.0\bin> .\mongo.exe "mongodb+srv://cluster0-jjbdh.mongodb.net/test" --username root
MongoDB shell version v4.0.8
Enter password:
connecting to: mongodb://cluster0-shard-00-01-jjbdh.mongodb.net.:27017,cluster0-shard-00-02-jjbdh.mongodb.net.:27017,cluster0-shard-00-00-jjbdh.mongodb.net.:27017/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0&ssl=true
2019-04-07T19:03:46.945+0300 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-01-jjbdh.mongodb.net.:27017,cluster0-shard-00-02-jjbdh.mongodb.net.:27017,cluster0-shard-00-00-jjbdh.mongodb.net.:27017
2019-04-07T19:03:58.840+0300 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-04-07T19:03:58.841+0300 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
2019-04-07T19:04:00.281+0300 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-04-07T19:04:00.282+0300 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.
2019-04-07T19:04:01.751+0300 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-04-07T19:04:01.752+0300 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 3 checks in a row.
2019-04-07T19:04:01.756+0300 E QUERY [js] Error: connect failed to replica set Cluster0-shard-0/cluster0-shard-00-01-jjbdh.mongodb.net.:27017,cluster0-shard-00-02-jjbdh.mongodb.net.:27017,cluster0-shard-00-00-jjbdh.mongodb.net.:27017 :
connect#src/mongo/shell/mongo.js:343:13
#(connect):2:6
exception: connect failed
and
.\mongo.exe "mongodb://root:password#cluster0-shard-00-00-jjbdh.mongodb.net:27017/admin"
MongoDB shell version v4.0.8
connecting to: mongodb://cluster0-shard-00-00-jjbdh.mongodb.net:27017/admin?gssapiServiceName=mongodb
2019-04-07T19:17:19.420+0300 E QUERY [js] Error: network error while attempting to run command 'isMaster' on host 'cluster0-shard-00-00-jjbdh.mongodb.net:27017' :
connect#src/mongo/shell/mongo.js:343:13
#(connect):2:6
exception: connect failed

The correct uri was
mongodb+srv://root:password#cluster0-jjbdh.mongodb.net/somebuddy?retryWrites=true
which is actually almost the uri suggested by atlas:
mongodb+srv://root:<password>#cluster0-jjbdh.mongodb.net/test?retryWrites=true

Related

Mongodb unable to connect to cluster

We are using mongodb community addition .
We are able to connect to independent nodes primary, and 2 replicas using direct connection.
But when we try to connect to replica set using url:-
mongodb://sorterapp:SorTErRwXpressXb#3.109.226.31:27017,15.207.33.131:27017,13.234.13.53:27017/?authSource=sorter&replicaSet=stagesorter
It is not able to connect.
Error:-
getaddrinfo ENOTFOUND primary
Not sure what is the error
We tried using mongo compass as well as application library

Error while connecting MongoDB ATLAS TO MONGO DB COMPASS

I am a beginer in mongoDB and learning Mongodb atlas.
In MongoDB Atlas, Under database access created username and password ( password is system generated and has no special character)
Under Network access added a public ip address (allow access from anywhere)
Under database deployment loaded sample database.
Now I wanted to see my cluster data, so wanted to connect it to vs code or MongoDB Compass. I clicked connect, selected connect using mongo db compass, copied the string.
now i opened Mongodb compass, and under New connection i.e connect to a MongoDB deployment, i entered my URL
mongodb+srv://gourav_singh:7gamf8UkL8B6MET#cluster0.9dmds.mongodb.net/test
clicked Connect
But i got error as : Unable to connect: connect ECONNREFUSED 3.6.85.199:27017
How I can fix it, Looking for kind help. Thanks in advance

When I execute rs.initiate() in Mongo DB its successful but compass gives connection error

I want to create a MongoDB 5.0 replica set on AWS EC2, When I create a standalone setup, it works completely fine. I can easily connect from anywhere. But when I convert this instance to a replica set with updating the mongod.conf and executing rs.initiate(), I cannot connect anymore!
My Mongo Compass gives the following error: getaddrinfo ENOTFOUND ip-172-31-14-219.eu-central-1.compute.internal

Not able to connect replica set of mongo DB in mongo-kafka source connect

Am using mongo kafka source connector v1.6.. Am trying to connect it replica set of mongo db
I have connection uri like this
mongodb://:#instance1:27017,instance2:27017,instance3:27017/?authSource=test&replicaSet=replicaset&ssl=true
the error am getting is
unable to connect server
... username and password is crct and also connectivity to DB also open
can u please tell what am doing wrong

Mongo DB BI Connector locally with remote db

I'm trying to create an ODBC connection with a remote mongoDB in order to connect MS Power BI with this mongo via ODBC.
By reading the mongoDB Connector documentation here (https://docs.mongodb.com/bi-connector/current/#:~:text=The%20MongoDB%20Connector%20for%20Business,Tableau%2C%20MicroStrategy%2C%20and%20Qlik) - Hosted Database and On Premises BI Connector, i am trying to connect to the remote mongodb with the --mongo-uri option when you start the BI Connector's mongosqld process.
here is the response i am receiving on this connection attempt:
If you can't see the image, the error is "unable to load mongodb information: failed to create admin session for loading server cluster information... socket was unexpectedly closed: EOF"
Does anybody know what i am missing on this connection?