遭遇此坑真是刻骨铭心。。。。。几乎找了半天的错误。。。查了API,看了好多人的代码。。。最后。。。终于发现是哪里有问题。。。
其实不记得这种写法怎么来的了。。。。= = 因为刚开始看代码的时候会点开很多教程看。。可能默默就错了。。。。
错误:
<span style="font-size:14px;color:#333333;">var db = mongoose.createConnection(setting.host, setting.db);
db.once('open',function(){
console.log('success');
var schema = mongoose.Schema({
title:String
});
var model = mongoose.model('all',schema);
var kit = new model({title: 'xxx'});
kit.save(function(err, date, num){
console.log('!');
if(err) console.log(err);
else if(date) console.log(date);
else console.log(num);
})
})</span>
现象:可以显示success,但是用save的时候却没有反应。。因为model是错的。。具体反应应该是要追溯到源码的。。。