javascript - Mongoose 5.3,this.getUpdate 不是函数
问题描述
当我尝试执行该update
功能时,出现此错误。它发生在我添加时timestamps: true
我导航到错误,我在 mongoose >> lib 文件夹中的 schema.js 中调用了这个函数。
function _setTimestampsOnUpdate(next) {
applyTimestampsToUpdate(createdAt, updatedAt, this.getUpdate(),
this.options, true);
applyTimestampsToChildren(this);
next();
}
上述函数与getUpdate
in一起使用schema.js
。请帮我解决这个问题。
:: 架构 ::
const assetListSchema = new Schema({userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
name: String,
config: {
showAssetsLibrary: {
type: Boolean,
required: true,
default: true
},
showAssetsDetails: {
type: Boolean,
required: true,
default: true
},
aliasName: {
type: String,
maxlength: 75,
default: ""
}
}},{ timestamps: true});
:: 更新功能 ::
assetListSchema.methods.update = async function (data) {
try {
let asst = this;
data = _.pick(data, ['showAssetsLibrary',
'showAssetsDetails','aliasName']);
if (_.isEmpty(data)) {
emptyError();
}
return await AssetsHierarchy.findByIdAndUpdate(asst._id, {
config: data
}, {
new: true,
fields: {
"config": 1
}
});
} catch (err) {
throw new Error(err.message);
}
}
:: 错误 ::
类型错误:this.getUpdate 不是函数
在 model._setTimestampsOnUpdate (D:\inspectionApp\inspection-backend\node_modules\mongoose\lib\schema.js:873:56)
在 callMiddlewareFunction (D:\inspectionApp\inspection-backend\node_modules\kareem\index.js:427:23)
在下一个 (D:\inspectionApp\inspection-backend\node_modules\kareem\index.js:58:7)
在 Kareem.execPre (D:\inspectionApp\inspection-backend\node_modules\kareem\index.js:86:8)
在 Kareem.wrap (D:\inspectionApp\inspection-backend\node_modules\kareem\index.js:265:8)
在 model.$__update (D:\inspectionApp\inspection-backend\node_modules\kareem\index.js:339:11)
在 utils.promiseOrCallback.callback (D:\inspectionApp\inspection-backend\node_modules\mongoose\lib\helpers\model\applyHooks.js:80:30)
在 Promise (D:\inspectionApp\inspection-backend\node_modules\mongoose\lib\utils.js:246:5)
在新的承诺 ()
在 Object.promiseOrCallback (D:\inspectionApp\inspection-backend\node_modules\mongoose\lib\utils.js:245:10)
在 model.objToDecorate.(匿名函数) [作为更新] (D:\inspectionApp\inspection-backend\node_modules\mongoose\lib\helpers\model\applyHooks.js:79:20)
更新时 (D:\inspectionApp\inspection-backend\App\controllers\settings\asset-hierarchy\assetsHierarchyController.js:163:33)
在 Layer.handle [as handle_request] (D:\inspectionApp\inspection-backend\node_modules\express\lib\router\layer.js:95:5)
在下一个(D:\inspectionApp\inspection-backend\node_modules\express\lib\router\route.js:137:13)
在 Route.dispatch (D:\inspectionApp\inspection-backend\node_modules\express\lib\router\route.js:112:3)
在 Layer.handle [as handle_request] (D:\inspectionApp\inspection-backend\node_modules\express\lib\router\layer.js:95:5)
解决方案
推荐阅读
- java - 如何在当前位置周围画一个圆圈?
- spring-boot - 带有 Spring-Boot、Gui 问题的 Vaadin Flow,
- binding - 获取未捕获(承诺)类型错误:将数据绑定到下拉列表时,对象(...)不是函数
- html - 随机化 flexbox 中 div 的顺序
- r - r将具有模式的列名从宽转换为长
- python - Python:使用正则表达式在大文本中选择文本
- java - 使用 springboot 和 hibernate 从 mysql db 检索的日志数据出现问题
- reactjs - 如何在我的组件中导入资源文件夹以避免“../../../resources/images/..”路径?
- c - 链表分段错误
- d3.js - 如何将文本添加到 d3.js 强制定向圆圈?