mongoose.connect('mongodb://localhost/guesswho');
var Schema = mongoose.Schema;
var Message = new Schema({
author: { type:String },
body: { type:String },
});
var MessageModel = mongoose.model("Message");
我按照这里的每条指示:https://github.com/LearnBoost/mongoose
但是我在运行时遇到此错误:Error: Schema hasn't been registered for model "Message".
我甚至试过这个:var MessageModel = mongoose.model("Message", Message);
当我这样做时......没有错误。但是,MessageModel未定义。
答案 0 :(得分:5)
修正:
var Message = new Schema({
author: { type:String },
body: { type:String },
});
mongoose.model("Message",Message);
var MessageModel = mongoose.model("Message");
var aMessage = new MessageModel();
aMessage.author = "apple";
aMessage.body = "orange";
aMessage.save(function(e){
});
来自IRC的人称coreb修复了它。