【发布时间】:2015-10-02 18:10:12
【问题描述】:
我让那些代码运行尝试将一个对象保存到MongoDB中。
.save() 从未成功运行。代码运行良好。
.save() 方法不起作用。
var conn = mongoose.createConnection(mongoUrl, {auth: {authdb: "admin"}});
conn.on('error', function (err) {
throw err;
});
conn.once('open', function callback() {
console.log("connected to " + mongoUrl);
var cacheSchema = mongoose.Schema({}, {strict: false});
cacheSchema.set('collection', 'caches');
// you need to specify which connection is uing.
var Cache = conn.model('cache', cacheSchema);
var measure = new Cache();
measure['test'] = "test";
measure.save(function(err){
console.log('test');
});
});
【问题讨论】:
-
the .save() never got success run你怎么知道?你没有给它回调。 -
怎么了?发布错误
-
我编辑了回调。我将断点放在 console.log() 处。它从未停止过