3

Trying to run a web app (MEAN) on Amazon EC2 Instance but am encountering the following problem. Can anyone help me with this?

node app.js The Server has started on 9091
/opt/bitnami/apps/YelpCamp/node_modules/mongodb-core/lib/auth/scram.js:128
    username = username.replace('=', "=3D").replace(',', '=2C');
                        ^

TypeError: Cannot read property 'replace' of undefined
    at executeScram (/opt/bitnami/apps/SomeApp/node_modules/mongodb-core/lib/auth/scram.js:128:24)
    at /opt/bitnami/apps/SomeApp/node_modules/mongodb-core/lib/auth/scram.js:277:7
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
elssar
  • 5,651
  • 7
  • 46
  • 71

1 Answers1

4

Mongoose can do auth in 2 ways:

1, Connection string: mongoose.connect('mongodb://username:password@host:port(usually 27017)/db') Where username and password are the respective username and password for that specific db, host would be the host where your db is hosted (so localhost or some domain/IP), port is the port mongo listens on, and db is the name of the db you want to connect to

2, Using options. From the docs: var options = { useMongoClinet: true, auth: {authdb: 'admin'}, user: 'myUsername', pass: 'myPassword', } mongoose.connect(uri, options);

I also faced the 'username undefined' error in the first approach, but I succeeded in the second approach.

[Reference] https://github.com/Automattic/mongoose/issues/4891

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
K. Symbol
  • 3,330
  • 1
  • 21
  • 22