1

I'm teaching myself how to use MongoDB and Node.Js, specifically I'm trying to setup Deployd (the open source api-building framework) which is built on top of mongo & node, and host it on Heroku. I'm following this tutorial:

http://www.icapps.com/open-source-alternative-for-parse/

My problem occurs when trying to connect to http://localhost:3000/ it throws up the error:

    GET /dashboard/ Error: failed to connect to [127.0.0.1:27017]
at null.<anonymous> (/Users/kimi/Documents/Web/deployd/deployd-demo/node_modules/deployd/node_modules/mongodb/lib/mongodb/connection/server.js:383:73)
at EventEmitter.emit (events.js:95:17)
at null.<anonymous> (/Users/kimi/Documents/Web/deployd/deployd-demo/node_modules/deployd/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:93:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/Users/kimi/Documents/Web/deployd/deployd-demo/node_modules/deployd/node_modules/mongodb/lib/mongodb/connection/connection.js:385:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickDomainCallback (node.js:459:13)

I know this has something to do with mongo not connecting to the server correctly. But am at a loss at how to fix this. Does anyone have any suggestions for this newbie?

Thank you so much!

/////////// ANSWER! (stackoverflow won't let me post an answer for another 8 hours), but basically it appears that the mongo directory was created in the wrong place. but running:

sudo mkdir -p /data/db

and changing the permissions to:

sudo chmod 0755 /data/db
sudo chown mongod:mongod /data/db

it appears to work. yay! i used this stackoverflow answer as a reference:

mongodb Mongod complains that there is no /data/db folder

thank you so much @Niall for all your help!!!

Community
  • 1
  • 1
vesperae
  • 1,291
  • 2
  • 19
  • 28

2 Answers2

1

1..it might be connection error, have you start mongod service?

$ mongod --host localhost --dbpath /var/lib/mongodb --logpath data/log/mongodb/mongodb.log

2..if you use Express@3, the connect-mongo might have default setting connect to [127.0.0.1:27017]

connect-mongo.js

$ vi .\node_modules\connect-mongo\lib\connect-mongo.js
...
var defaultOptions = {
  // Legacy strategy default options
  host: '127.0.0.1',
  port: 27017,
...

in your app.js

var settings = require('./settings');
...
var MongoStore = require('connect-mongo')(express);
var sessionStore = new MongoStore({
    host: settings.host, //define this, otherwise it throws "Error: failed to connect to [1276.0.0.1:27017]"
    port: settings.port,
    db: settings.db
}, function () {
    console.log('connect mongodb success...');
});

in your settings.js could set like this:

module.exports = {
    cookie_secret : 'secret_meteoric',
    db : 'test',
    host : '192.168.0.190',  //your mongod host
    port : 27017
};

then you can connect your default mongod when app start. hope it helps.

Yuqi Li
  • 31
  • 1
  • 6
-1

i was also waste a lot of time in this issue.and then after found an silly issue. i was installing Pencilblue. in which you should go on root folder of pencilblue.

  1. find "sample.config.json"
  2. Edit it "config.json".``
  3. and thenafter in gitbash --> type "pbctrl start"

its worked for me. For Mongodb installation for windows you can refer http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/ may be it will help some one..

isherwood
  • 58,414
  • 16
  • 114
  • 157