Node.js + Mongoose works locally, but not on Heroku Node.js + Mongoose works locally, but not on Heroku heroku heroku

Node.js + Mongoose works locally, but not on Heroku


Did you specify node version in heroku?

please refer this. ( I also confused same issue. but resolved.)http://devcenter.heroku.com/articles/nodejs-versions


Your call to .save() takes a callback function. Try adding a debug message in there and see if it shows any information about why its failing, like this:

Msg.save(function(err){  if(err){     console.log("Error:", err);  }else{    console.log("success");  }})

Then you should be able to see the result in the heroku logs.


Another possible source of confusion is if you are sourcing both MongoLab and MongoHQ, then the default connection string provided in the Heroku tutorial will break your DB session:

var mongoUri = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || 'mongodb://localhost/mydb';

i.e.: if you are using MongoHQ only with both installed, you should throw away the process.env.MONGOLAB_URI