簡體   English   中英

無法使用Mongoose使用Bitnami MEAN STACK連接到MongoDB

[英]Cannot Connect to MongoDB with Bitnami MEAN STACK using Mongoose

我從AWS(具體來說是Bitnami)購買了MEAN技術堆棧,並且一直熱衷於學習如何部署我的第一個節點應用程序。 但是,實際上要使我的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);
});

我在這里遵循了教程

而且我不斷收到這個錯誤

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的方法。...我已經呆了兩天了。

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

如果要使用管理數據庫,則需要使用以下行:

mongoose.createConnection('mongodb://root:pwdremoved@/opt/bitnami/mongodb/tmp/mongodb-27017.sock/admin');

如果您不想使用root用戶和admin密碼,可以查看本指南以了解如何創建數據庫並向新用戶授予特權。

https://wiki.bitnami.com/Components/mongoDB#How_to_create_a_database_for_a_custom_application.3f

我安裝了Meanstack 3.0.3-0,並按照Wiki中有關如何創建示例TODO列表的教程進行操作,一切正常。 您可以通過以下鏈接檢查它。

https://wiki.bitnami.com/index.php?title=Infrastructure_Stacks/BitNami_MEAN_Stack_(MongoDB%2C_Express%2C_Angular%2C_Node.js)#How_to_create_a_sample_TODO_list_project_with_MEAN.3f

我希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM