Node.js + Mongoose在本地运行,但不在Heroku上运行 [英] Node.js + Mongoose works locally, but not on Heroku

查看:104
本文介绍了Node.js + Mongoose在本地运行,但不在Heroku上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在Heroku上运行的node.js文件。它在本地完美工作,但是当我将它推到Heroku时,数据库集合不会创建,也不会引发错误。最终,我只是试图在Heroku上运行时实际创建连接。谢谢。

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();


推荐答案

您是否在heroku中指定节点版本?

Did you specify node version in heroku?

请参阅此。 (我也混淆了同样的问题,但解决了。)
http://devcenter.heroku.com/articles/nodejs -versions

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

这篇关于Node.js + Mongoose在本地运行,但不在Heroku上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆