我从AWS购买了MEAN技术堆栈(Bitnami是具体的),并且一直在热切地学习如何部署我的第一个节点应用程序。但是,我已经打了这么多墙,实际上让我的mongo连接工作。 我已阅读文档并尝试了各种方法来解决下面的问题
根管理员密码已重置。以下是我使用正确的用户名和密码
的证明> bitnami@ip-172-31-43-127:~/edupal$ sudo mongo admin --username root --password
pwdremoved
MongoDB shell version: 3.0.3
connecting to: /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017/admin
Server has startup warnings:
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten]
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten] ** NOTE: This is a 32 bi
t MongoDB binary.
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten] ** 32 bit builds a
re limited to less than 2GB of data (or less with --journal).
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten] ** See http://doch
ub.mongodb.org/core/32bit
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten]
> show dbs
admin 0.078GB
local 0.078GB
users 0.078GB
> use users
switched to db users
> db.myCollection.find()
{ "_id" : ObjectId("5578c11040a096b7fef84aad"), "name" : "Bill", "score" : "9" }
到目前为止,我相信我在资历方面表现出色。这是我连接到我的数据库的方式
// Connect to MongoDB
mongoose.createConnection('mongodb://root:pwdremoved@/opt/bitnami/mongodb/tmp/
mongodb-27017.sock/admin');
mongoose.connection.once('open', function() {
// Load the models.
app.models = require('./models/index');
// Load the routes.
var routes = require('./routes');
_.each(routes, function(controller, route) {
app.use(route, controller(app, route));
});
console.log('Listening on port 3000...');
app.listen(8080);
});
我按照教程here
进行了操作我一直收到此错误
bitnami@ip-172-31-43-127:~/edupal$ npm start
> app@0.0.0 start /home/bitnami/edupal
> node ./bin/www
events.js:85
throw er; // Unhandled 'error' event
^
Error: failed to connect to [/opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017]
at null.<anonymous> (/home/bitnami/edupal/node_modules/mongoose/node_modules
/mongodb/lib/mongodb/connection/server.js:555:74)
at emit (events.js:118:17)
at null.<anonymous> (/home/bitnami/edupal/node_modules/mongoose/node_modules
/mongodb/lib/mongodb/connection/connection_pool.js:150:15)
at emit (events.js:110:17)
at Socket.<anonymous> (/home/bitnami/edupal/node_modules/mongoose/node_modul
es/mongodb/lib/mongodb/connection/connection.js:534:10)
at Socket.emit (events.js:107:17)
at net.js:459:14
at process._tickCallback (node.js:355:11)
npm ERR! Linux 3.13.0-53-generic
npm ERR! argv "/opt/bitnami/nodejs/bin/.node.bin" "/opt/bitnami/nodejs/bin/npm"
"start"
npm ERR! node v0.12.4
npm ERR! npm v2.11.1
npm ERR! code ELIFECYCLE
npm ERR! app@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@0.0.0 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls app
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/bitnami/edupal/npm-debug.log
我不确定我做错了什么,尝试了很多连接到MongoDB的变种....我已经被困了两天了。
答案 0 :(得分:1)
Bitnami开发者在这里。
您发布了可以使用root用户
连接到管理数据库的信息bitnami@ip-172-31-43-127:~/edupal$ sudo mongo admin --username root
--password pwdremoved MongoDB shell version: 3.0.3 connecting to: /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017/admin
但后来你试图连接到“索引”数据库
mongoose.createConnection('mongodb://root:pwdremoved@/opt/bitnami/mongodb/tmp/mongodb-27017.sock/indexes');
是否创建了该数据库?您可以使用以下命令检查创建的数据库:
show dbs
如果您想使用admin数据库,则需要使用以下行:
mongoose.createConnection('mongodb://root:pwdremoved@/opt/bitnami/mongodb/tmp/mongodb-27017.sock/admin');
如果您不想使用root用户和管理员密码,可以查看本指南以了解如何创建数据库并向新用户授予权限。
https://wiki.bitnami.com/Components/mongoDB#How_to_create_a_database_for_a_custom_application.3f
我安装了Meanstack 3.0.3-0,我按照wiki中关于如何创建示例TODO列表的教程,一切正常。您可以通过以下链接查看。
我希望这会有所帮助。