mongo icon indicating copy to clipboard operation
mongo copied to clipboard

Bad auth

Open aleksre opened this issue 3 years ago • 3 comments

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/[email protected]/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`)

aleksre avatar Jul 05 '21 18:07 aleksre

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

Nastradoomus avatar Oct 03 '21 11:10 Nastradoomus

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.

justinmchase avatar Jan 28 '22 02:01 justinmchase

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

bobmoff avatar Jan 22 '23 13:01 bobmoff