0
我運行的是貓鼬findByIdAndUpdate功能(模型靜態函數內部):貓鼬功能findByIdAndUpdate返回一個空文件
TemplateSchema.statics.archive = function(templateId, userId, callback) {
let now = new Date();
this.model('Template').findByIdAndUpdate(templateId, {
discon: true,
discon_date: now,
discon_user_id: userId
}, {new: true}, function(err, templateDoc){
if(err){
console.log("err:",err);
}
else{
console.log("templateDoc:",templateDoc);
}
});
};
控制檯打印出templateDoc: null
。任何想法爲什麼?
注: 在模板架構,指定了_id
領域爲:
_id: {type: String}
當我做console.log(typeof templateId)
,運行findByIdAndUpdate
功能之前,它顯示爲string
。
我正在使用Mongoose v4.7.6。
我已檢查文檔確實存在於Mongo數據庫中。
我已經檢查了Mongo的_id
字段的類型,它是String
。