denodrivers / mongo

🍃 MongoDB driver for Deno 🦕
https://deno.land/x/mongo
MIT License
509 stars 95 forks source link

Bad auth #210

Open aleksre opened 3 years ago

aleksre commented 3 years ago

After upgrading to latest version from v.0.13.0, I am no longer able to connect to the cluster.

error: Uncaught (in promise) Error: MongoError: "Connection failed: MongoError: {\"ok\":0,\"errmsg\":\"bad auth : Authentication failed.\",\"code\":8000,\"codeName\":\"AtlasError\"}"
      throw new MongoError(`Connection failed: ${e.message || e}`);

I know the auth is correct because it works with compass from the same computer, and of course the same user/password worked just fine with the old version. Nothing has changed in atlas and my IP is whitelisted.

Code:

import { MongoClient } from 'https://deno.land/x/mongo@v0.23.1/mod.ts'

const dbuser = 'dbUser'
const dbpass = 'redacted'
const dbname = 'mydb'

const client = new MongoClient()
await client.connect({
    db: dbname,
    tls: true,
    servers: [{
        host: 'cluster0-shard-00-01.skgsx.mongodb.net',
        port: 27017,
    }],
    credential: {
        username: dbuser,
        password: dbpass,
        db: dbname,
        mechanism: 'SCRAM-SHA-1',
    },
})

const db = client.database(dbname)

I have also tried with: await client.connect(`mongodb+srv://${dbuser}:${dbpass}@cluster0.skgsx.mongodb.net/${dbname}?retryWrites=true&w=majority&authMechanism=SCRAM-SHA-1`)

Nastradoomus commented 3 years ago

Try to shorten username and pass global admin priviledges to that user. Both of these helped me to get connection.

justinmchase commented 2 years ago

The connection string approach worked for me, I don't see anything wrong with yours. I couldn't get the full object version to work, not sure why.

bobmoff commented 1 year ago

Adding authMechanism=SCRAM-SHA-1 to the connection string worked for me...