Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection error #206

Open
garrigaj opened this issue Jun 6, 2021 · 14 comments
Open

Connection error #206

garrigaj opened this issue Jun 6, 2021 · 14 comments
Labels
atlas Everything About MongoDB Atlas

Comments

@garrigaj
Copy link

garrigaj commented Jun 6, 2021

I am getting this error when I try to connect:
error: Uncaught (in promise) Error: MongoError: "Connection failed: Invalid hostname: 'cluster0.gpkxo.mongodb.net?retryWrites=true&w=majority'"
throw new MongoError(Connection failed: ${e.message || e});
^
at MongoClient.connect (https://deno.land/x/[email protected]/src/client.ts:93:15)
at async MongoDBConnector._makeConnection (https://deno.land/x/[email protected]/lib/connectors/mongodb-connector.ts:44:7)
at async MongoDBConnector.query (https://deno.land/x/[email protected]/lib/connectors/mongodb-connector.ts:65:5)
at async Database.query (https://deno.land/x/[email protected]/lib/database.ts:240:21)
at async Function.createTable (https://deno.land/x/[email protected]/lib/model.ts:172:5)
at async Database.sync (https://deno.land/x/[email protected]/lib/database.ts:210:7)

I used the code example from the home page:
db: 'todo-app',
tls: true,
servers: [
{
host: 'cluster0.gpkxo.mongodb.net?retryWrites=true&w=majority',
port: 27017,
},
],
credential: {
username: '<my_username>',
password: '<my_password>',
db: 'todo-app',
mechanism: 'SCRAM-SHA-1',
},

I also verified that the password was available by resetting and I made sure I had whitelisted my IP address.

@manyuanrong
Copy link
Member

Try to connect using URI

@garrigaj
Copy link
Author

garrigaj commented Jun 7, 2021

I did and got the same error message.

@manyuanrong
Copy link
Member

There is a problem with the domain name resolution. Are you sure your domain name is correct? Can you connect through other client tools?

@garrigaj
Copy link
Author

garrigaj commented Jun 8, 2021

I connect with Mongoose on Node.js using the full URI without issues. When I use either the full URI or the more detailed method here, I can't connect.

@manyuanrong
Copy link
Member

host should only contains cluster0.gpkxo.mongodb.net

@garrigaj
Copy link
Author

garrigaj commented Jun 8, 2021

Tried it. It still didn’t work. I also tried with and without the Mongo protocol and still could not connect.

@manyuanrong
Copy link
Member

I don't know what you tried and whether you constructed the parameters correctly. Just believe that you did the right thing. By the way, can your domain name be resolved successfully through ping or route?
(give me the result of your attempt)

@garrigaj
Copy link
Author

garrigaj commented Jun 8, 2021

I can connect with Mongoose, MongoDB Compass, and Node.js MongoDB driver with the URI. I cannot connect with this library.

@manyuanrong
Copy link
Member

Perhaps your database is on an internal network. You can give me the results of your investigation. Like this,
image

@garrigaj
Copy link
Author

garrigaj commented Jun 8, 2021

That is the URI MongoDB Atlas gives me. Everything, except this driver, that I use to connect to it works: "mongo+srv://garrigaj:[email protected]/db_name?retryWrites=true&w=majority"

@RNR1
Copy link
Contributor

RNR1 commented Jun 20, 2021

What made it possible for me to connect via URI is adding the "authMechanism" param exactly like shown below. I also added it to the docs here a few weeks ago.

await client.connect(
  "mongodb+srv://<username>:<password>@<db_cluster_url>/<db_name>?authMechanism=SCRAM-SHA-1",
);

@GlennGuegan
Copy link

Hello 🙂
If you use Mongo Atlas you should add your IP public address as available in Network Access section

@lucsoft lucsoft added the atlas Everything About MongoDB Atlas label Apr 11, 2022
@toridoriv
Copy link

What made it possible for me to connect via URI is adding the "authMechanism" param exactly like shown below. I also added it to the docs here a few weeks ago.

await client.connect(
  "mongodb+srv://<username>:<password>@<db_cluster_url>/<db_name>?authMechanism=SCRAM-SHA-1",
);

Thanks! This worked perfectly 💜

@marcelovicentegc
Copy link

What made it possible for me to connect via URI is adding the "authMechanism" param exactly like shown below. I also added it to the docs here a few weeks ago.

await client.connect(
  "mongodb+srv://<username>:<password>@<db_cluster_url>/<db_name>?authMechanism=SCRAM-SHA-1",
);

Just for the record. I was also facing this issue and adding the authMechanism solved the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
atlas Everything About MongoDB Atlas
Projects
None yet
Development

No branches or pull requests

7 participants