Mongoose return data inside
On mongoose find query execution, response data as multiple objects, the real data is in _doc property or field, its only occurs in some scenario. I can handle the data by getting Obj._doc.something, but i cant edit the data and save(mongoose model function). please help me to resolve this problem.
Note: Fields for schema has added dynamically.
PatientOrderMigration.find({ mrn: orderitem.mrn, visituid: orderitem.visituid },
function (err, orderDoc)
{
//log data correctly.
console.log(orderDoc);
// undefined
console.log(orderDoc._id);
// correct data
console.log(orderDoc._doc._id);
}
Well, Model.find()
will Give you Array of objects found on DB, if you want to access directly to your object you can use Model.findOne()
OR => A quick Fix :
PatientOrderMigration.find({ mrn: orderitem.mrn, visituid: orderitem.visituid },function (err, orderDoc) {
orderDoc = orderDoc[0];//Here is the Fix, you can comment this if you use findOne
orderDoc.mrn = "New Value you want to update";
orderDoc.save(function(err, result){
console.log('err',err)
})
}}
链接地址: http://www.djcxy.com/p/89570.html
上一篇: Mongoose pre.remove中间件中的对象不会被调用
下一篇: 里面的Mongoose返回数据