MongoDB Auth Fails to find username on Bitnami MEAN Stack Image

荒凉一梦 提交于 2019-12-11 02:02:20

问题


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)

回答1:


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



来源:https://stackoverflow.com/questions/47587318/mongodb-auth-fails-to-find-username-on-bitnami-mean-stack-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!