1
嘿所有試圖使用express和mongoose與nodejs MVC一起玩。Coffee-Script Nodejs和Mongoose
我有以下代碼:
mongoose = require 'mongoose'
Schema = mongoose.Schema
mongoose.connect 'mongodb://localhost/quotes'
Quote = new Schema()
Quote.add {
quote : { type: String, required: true}
, rank : Number
}
quote = new mongoose.model 'Quote', Quote
module.exports =
index: (req,res, next) ->
quote.find {}, (err,docs) ->
res.render docs
當我去運行服務器,我收到以下內容:
Server started on port 3000
module.js:311
throw err;
^
TypeError: Cannot read property 'Quote' of undefined
at new <anonymous> (/Users ....
我不能工作了,爲什麼它不斷拋出未定義錯誤。
編輯:
以下是編譯JS
var Quote, Schema, mongoose, quote;
mongoose = require('mongoose');
Schema = mongoose.Schema;
mongoose.connect('mongodb://localhost/quotes');
Quote = new Schema();
Quote.add({
quote: {
type: String,
required: true
},
rank: Number
});
quote = new mongoose.model('Quote', Quote);
module.exports = {
index: function(req, res, next) {
return quote.find({}, function(err, docs) {
return res.render(docs);
});
}
};
生成的javascript看起來像什麼? – 2012-04-16 08:08:25
我已經添加到您的問題:o) – Menztrual 2012-04-16 08:11:28