我的应用正在尝试使用以下命令建立与EC2上的mongoDB的连接:
mongoose.connect("mongodb://username:password@ec2-xx-xxx-x-xxx.us-west-2.compute.amazonaws.com:27017/databasename")
我在服务器上打开了端口27017和28017。只是为了验证我也打开了所有流量,这不是一个好主意。
我也可以通过mongo连接没问题:
mongo admin --username username -p --host ec2-xx-xxx-x-xxx.us-west-2.compute.amazonaws.com --port 27017
当我运行应用程序时,我收到以下错误:
/home/ubuntu/workspace/website.com/appname/node_modules/mongoose/node_modules/mongodb/lib/utils.js:99
process.nextTick(function() { throw err; });
^
MongoError: Authentication failed.
at Function.MongoError.create (/home/ubuntu/workspace/website.com/appname/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)
at /home/ubuntu/workspace/website.com/appname/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:483:72
at authenticateStragglers (/home/ubuntu/workspace/website.com/appname/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:429:16)
at null.messageHandler (/home/ubuntu/workspace/website.com/appname/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:463:5)
at Socket.<anonymous> (/home/ubuntu/workspace/website.com/appname/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:309:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:536:20)
答案 0 :(得分:1)
您似乎没有为要尝试连接的数据库创建用户。我将使用admin用户连接MongoDB并创建它:
justify/align-items