Here's my node.js file I'm running on Heroku. It works perfectly locally, but when I push it to Heroku, the database collection isn't created and no errors are thrown. Ultimately I'm just trying to get it to actually creating the connection while it's running on Heroku. Thanks.
var mongoose = require('mongoose'),
db_url = process.env.MONGOHQ_URL || "mongodb://john:<mypasswordwashere>@staff.mongohq.com:10053/app3305538",
db = mongoose.connect(db_url),
Schema = mongoose.Schema;
//Mongoose DB Test
var MsgSchema = new Schema({
date: {type: Date, default: Date.now},
message: String
});
var MsgModel = db.model("messages", MsgSchema);
var Msg = new MsgModel();
Msg.message = "blurgh";
Msg.save();
ObjectRocket for MongoDB can be attached to a Heroku application via the CLI: A list of all plans available can be found here. $ heroku addons:create ormongo:5-mmap Creating ormongo-infinite-92036...
It's not mandatory to use Mongoose over the MongoDB Native API. However, there are some benefits to doing so.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With