question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to connect to mongodb Atlas

See original GitHub issue

Hey, it works with local db but fails with mongodb atlas connection string, I’m using the syntax like this:

await client.connect(
    "mongodb+srv://user:password@name.mongodb.net/db?authMechanism=SCRAM-SHA-1"
);

// also tried this

await client.connect(
    "mongodb+srv://user:password@name.mongodb.net/db?retryWrites=true&w=majority&authMechanism=SCRAM-SHA-1"
);

// and this

await client.connect(
    "mongodb+srv://user:password@name.mongodb.net/db?retryWrites=true&w=majority"
);

It always fails here: https://deno.land/x/mongo@v0.29.0/src/client.ts#L41 with error:

{
"ok":0,
"errmsg":"Authentication failed.",
"code":18,
"codeName":"AuthenticationFailed",
"$clusterTime":{"clusterTime":{"$timestamp":"7043035952079437828"},"signature":{"hash":"z8hkCMby/OYpTnJXHNS7+rZfBvI=","keyId":{"high":1625418439,"low":1,"unsigned":false}}},
"operationTime":{"$timestamp":"7043035952079437828"}
}

Can you share if it’s a known issue or do I need to provide some additional params?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
playerxcommented, Dec 21, 2021

Ah it seems the database name in the connection string isn’t supported for now. It started working once I’ve updated connection string like this:

 "mongodb+srv://USER:PASSWORD@jok-prod.RANDOM.mongodb.net/?authMechanism=SCRAM-SHA-1"
0reactions
playerxcommented, Dec 21, 2021

The reason why I think it’s an issue is that the connection string I used works properly with nodejs mongo (official) driver and many users will use the same connections string and had the same issue.

I think credential.db should not be changed unless there will be provided authSource explicitly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't connect to mongodb.Could not connect to any ...
First try to Allow Access From Anywhere. If it works it is most likely because you whitelisted an IP address that is not...
Read more >
node.js - Error at connecting to MongoDb Atlas Server
I have had this issue connecting to a MongoDB Atlas cluster. I have had to resolve this ... Once I turned off my...
Read more >
Can't connect to MongoDB atlas serverless instance
Hi, i have a MongoDB serverless instance but i can't connect to that. I am using the connection string that mongo atlas gives...
Read more >
Cannot connect to MongoDB atlas
Hey guys. I recently deployed my app on Netlify and so far, everything is pretty good; however I cannot connect to my mongoDB...
Read more >
Unable to connect to Mongo Atlas Cluster · Issue #6678
@ayukidawe I had this same issue for a month now. Since you are connecting to MongoAtlas, connect to your second or third node,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found