Mongoose如何在插入时获取index
Mongoose如何在插入时获取index: var dbo = new DBO(); var Model = dbo.getModel(this.collectionName, this.schema); var model = new Model(this.getValue()); var user = this; model.save(function(err,model,numberAffected) { if (err) consle.log(err);
console.log('---------------------------------');
console.log(model);
console.log('---------------------------------');
user = model.get('_id');
return true;
});
为何model已经在插入后传入方法中了,为了还是无法获取_id???
4 回复
完全没看懂这是在干嘛…
model.save(function(err,newModel,numberAffected) {
if (err){
consle.log(err);
}
console.log('---------------------------------');
console.log(newModel);
console.log('---------------------------------');
user = newModel.id;
return true;
});
这样试试
model.get(’_id’); ===> model._id
按照你们的方法都试过了 还是返回Null