0

I am trying to connect with MongoDB by mongoose. Everything was ok, when I was connecting with my local db where there is no authentication. When I've tried to connect to other DB with set admin user and credentials, I've got error and I've tried various different options but without any positive result. I use these versions:

    "mongodb": "^3.3.2",
    "mongoose": "^5.7.1"

And my server side technology is node.js

I've tried these options:

const connection = await mongoose.connect(`mongodb://${host}:${port}/${db}?authSource=admin`,
{ useNewUrlParser: true, useUnifiedTopology: true });

then I've tried this:

 let options = {
   "auth": { "authSource":"admin"},
    "user": "SVSAdmin",
    "pass":"8&PG2DCUuDPvy$hx",
    "useUnifiedTopology": true, 
    "useNewUrlParser": true
  };

const connection = await mongoose.connect(`mongodb://${host}:${port}/${db}, options);

and this:

mongoose.connect('mongodb://${user}:${pass}@${uri}/${db}?authMechanism=SCRAM-SHA-1')
mongoose.connect('mongodb://${user}:${pass}@${uri}/${db}?authMechanism=MONGODB-CR')

and also this:

mongoose.connect('mongodb://user:password@host/yourDB?authSource=admin&w=1')

but it does not work. My credentials are ok.

The error message is:

{
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {}
}

Maybe important thing is that I'm connecting with db by ssh I would be grateful for any help.

Malwafro
  • 17
  • 7

1 Answers1

0

If u are using ur database remotly then u can use it via IP.

db = mongodb://52.221.52.32/DataBaseName
Ankit Kumar Rajpoot
  • 5,188
  • 2
  • 38
  • 32