Cannot Connect to MongoDB with Bitnami MEAN STACK using Mongoose

2k views Asked by At

I purchased the MEAN tech stack from AWS (Bitnami to be specific) and have been eagerly trying to learn how to deploy my first node app. However, I have been hitting so many walls with actually getting my mongo connection to work. I have read documentation and tried various recipes to fix the issue below

The root admin password has been reset. Here is the proof that I am using the correct pair of username and password

> 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" }

So far, I believe I am in good standing in terms of credentials. Here is how I am connecting to my database

// 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);
});

I followed the tutorial here

and I keep getting this error

bitnami@ip-172-31-43-127:~/edupal$ npm start

> [email protected] 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! [email protected] start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

I am not sure what I am doing wrong and have tried many variations of connecting to MongoDB....I've been stuck for two days now.

1

There are 1 answers

1
Jota Martos On

Bitnami developer here.

You posted that you can connect to the admin database using the root user

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

but later you tried to connect to the "indexes" database

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

Is that database created? You can check the created databases with this command:

show dbs

If you want to use the admin database you will need to use this line:

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

You could check this guide to learn how to create a database and grant privileges to a new user if you don't want to use the root user and the admin password.

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

I installed Meanstack 3.0.3-0 and I followed the tutorial in our wiki about how to create a sample TODO list and everything works fine. You can check it the following link.

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

I hope this helps.