尝试在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)
答案 0 :(得分:2)
Mongoose可以通过两种方式进行身份验证:
1,连接字符串:
mongoose.connect('mongodb://username:password@host:port(usually 27017)/db')
如果用户名和密码是该特定数据库的相应用户名和密码,则主机将是托管数据库的主机(因此为localhost或某些域/ IP),port是mongo侦听的端口,db是要连接到
2,使用选项。来自文档:
var options = {
useMongoClinet: true,
auth: {authdb: 'admin'},
user: 'myUsername',
pass: 'myPassword',
}
mongoose.connect(uri, options);
我在第一种方法中也遇到了“用户名未定义”的错误,但我在第二种方法中取得了成功。