mongo
mongo copied to clipboard
Bad auth
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`)
Try to shorten username and pass global admin priviledges to that user. Both of these helped me to get connection.
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.
Adding authMechanism=SCRAM-SHA-1 to the connection string worked for me...