var mongo = require('mongoose');
var connection = mongo.createConnection('mongodb://127.0.0.1/test');
connection.on("error", function(errorObject){
console.log(errorObject);
console.log('ONERROR');
});
var Schema = mongo.Schema;
var BookSchema = new Schema({ title : {type : String, index : {unique : true}}});
var BookModel = mongo.model('abook', BookSchema);
var b = new BookModel({title : 'aaaaaa'});
b.save(function(e){
if(e){
console.log('error')
}else{
console.log('no error')
}});
'error'或'no error'都不會打印到終端。更重要的是,connection.on'錯誤'似乎也不會觸發。我已經確認MongoDb正在運行。Mongoose.js instance.save()callback not firing
感謝@aaronheckmann! – LDK 2012-04-23 22:05:31
謝謝,向mongoosejs.com的教程提交了一個修復程序。 – 2013-05-18 22:51:41
@aaronheckmann,當將'mongo.model'更改爲'connection.model'我得到'TypeError:未定義的類型'paths.login'您嘗試嵌套架構嗎?你只能使用參考或數組嵌套.' – 2014-03-28 12:32:04