我的應用程序成功地在我的本地服務器上運行。Heroku服務器上NodeJS應用程序中的MissingSchemaError
2012-12-28T10:00:53+00:00 heroku[web.1]: Starting process with command `node server.js`
2012-12-28T10:00:54+00:00 app[web.1]:
2012-12-28T10:00:54+00:00 app[web.1]: /app/node_modules/mongoose/lib/index.js:261
2012-12-28T10:00:54+00:00 app[web.1]: throw new mongoose.Error.MissingSchemaError(name);
2012-12-28T10:00:54+00:00 app[web.1]: ^
2012-12-28T10:00:54+00:00 app[web.1]: MissingSchemaError: Schema hasn't been registered for model "Activity".
2012-12-28T10:00:54+00:00 app[web.1]: Use mongoose.model(name, schema)
2012-12-28T10:00:54+00:00 app[web.1]: at Mongoose.model (/app/node_modules/mongoose/lib/index.js:261:13)
2012-12-28T10:00:54+00:00 app[web.1]: at Object.<anonymous> (/app/app/models/user.js:8:25)
2012-12-28T10:00:54+00:00 app[web.1]: at Module._compile (module.js:449:26)
2012-12-28T10:00:54+00:00 app[web.1]: at Object.Module._extensions..js (module.js:467:10)
2012-12-28T10:00:54+00:00 app[web.1]: at Module.load (module.js:356:32)
2012-12-28T10:00:54+00:00 app[web.1]: at Function.Module._load (module.js:312:12)
2012-12-28T10:00:54+00:00 app[web.1]: at Module.require (module.js:362:17)
2012-12-28T10:00:54+00:00 app[web.1]: at require (module.js:378:17)
2012-12-28T10:00:54+00:00 app[web.1]: at /app/server.js:23:3
2012-12-28T10:00:54+00:00 app[web.1]: at Array.forEach (native)
2012-12-28T10:00:55+00:00 heroku[web.1]: Process exited with status 1
2012-12-28T10:00:55+00:00 heroku[web.1]: State changed from starting to crashed
在我server.js,我加載模式使用此代碼:
當我把它推到一個Heroku的服務器,有時它與此錯誤崩潰
var models_path = __dirname + '/app/models'
fs.readdirSync(models_path).forEach(function (file) {
require(models_path+'/'+file)
})
和我activity.js是:
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, moment = require('moment')
var schemaOptions = {
toJSON: {
virtuals: true
}
};
var ActivitySchema = new Schema({
venue: {type : Schema.ObjectId, ref : 'Venue'}
, user: {type : Schema.ObjectId, ref : 'User'}
, createdAt: {type : Date, default : Date.now}
, rate: Number
, message : String
, source : String
}, schemaOptions)
mongoose.model('Activity', ActivitySchema)
ActivitySchema.index({ "user": 1, "venue" : 1 }, { unique: true })
var modifiedAt = require('../../config/plugins.js');
ActivitySchema.plugin(modifiedAt, { index: false });
ActivitySchema.virtual('summary').get(function() {
moment.lang('en');
return moment(this.createdAt).fromNow() + ' via ' + this.source;
});
奇怪的是,有時應用程序崩潰,但有時它的工作原理。我能做些什麼來解決它?