0

I'm trying to connect to a Railway MongoDB I set up with expressJS but I keep getting an "Authentication Failed" Error.

Here is my code:

import  mongoose from "mongoose";

const connect = async () => {
    mongoose.connect('mongodb://mongo:password@myhost.railway.app:6949')
        .then(() => console.log('Connected to database movieDB'))
        .catch((err: any) => console.log(err));
}

connect();

I can connect to the database using MongoDB Compass and the Intellij Database tool, so the url should be correct.

Robert
  • 7,394
  • 40
  • 45
  • 64

1 Answers1

0

Maybe you should define dbName in options:

await db.connect(url, {
  dbName: 'test',
  retryWrites: true,
  w: 'majority'
})
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
sir
  • 1