MongoDB Auth无法在Bitnami MEAN Stack Image上找到用户名

问题描述 投票:2回答:1

尝试在Amazon EC2实例上运行Web应用程序(MEAN)但遇到以下问题。谁能帮我这个?

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)
node.js mongodb amazon-ec2 bitnami
1个回答
2
投票

Mongoose可以通过两种方式进行身份验证:

1,连接字符串: mongoose.connect('mongodb://username:password@host:port(usually 27017)/db') 其中用户名和密码是该特定数据库的相应用户名和密码,主机将是托管数据库的主机(因此localhost或某些域/ IP),端口是mongo侦听的端口,并且db是要连接的数据库的名称

2,使用选项。来自文档: var options = { useMongoClinet: true, auth: {authdb: 'admin'}, user: 'myUsername', pass: 'myPassword', } mongoose.connect(uri, options);

我在第一种方法中也遇到了“用户名未定义”错误,但我在第二种方法中取得了成功。

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

© www.soinside.com 2019 - 2024. All rights reserved.