无法在Node.js中的castArrayFilters中读取未定义的属性'castForQuery' [英] Cannot read property 'castForQuery' of undefined at castArrayFilters in Node.js
问题描述
我在 findOneAndUpdate ( mongoose )中使用 arrayFilters 作为选项更新 的值TimetableModel中的名称和 isRecursive 字段。
字段正在 MongoDb 中更新成功,但我还收到了异常,这是在此查询结尾处添加的。
I am using arrayFilters as option in findOneAndUpdate (in mongoose) to update value of name and isRecursive fields in TimetableModel. The fields are updating successfully in MongoDb but also I am getting the exception, which is being added at the end of this query.
我应该做些什么来消除这种异常?
What am I supposed to do to eliminate this exception?
以下是我的工作细节:
Following are the details of my work:
版本:mongodb:^ 3.1.13,
mongoose: ^ 5.4.9,
Versions: "mongodb": "^3.1.13", "mongoose": "^5.4.9",
这是架构:
const timetableSchema = new Schema({
individualId: {
type: Schema.Types.ObjectId,
required: true
},
date: {
type: Number,
required: false
},
time: []});
这是逻辑:
TimetableModel.findOneAndUpdate({
individualId: req.query.individualId,
date: req.query.date,
}, {
'time.$[i].name': req.query.name,
'time.$[i].isRecursive': req.query.isRecursive,
}, {
arrayFilters: [{
'i.timeSlot': req.query.timeSlot
}],
}, function (err, result) {
if (result) {
resolve(result);
} else if (err) {
reject(err);
}
}).catch((err) => {
reject(err);
})
这是例外
TypeError:无法在castArrayFilters(/ Users / user / Desktop / Projects / ParentsPlus / ParentsPlusRepo / parents-plus)读取未定义
的属性'castForQuery' -back端/ node_modules /猫鼬/ LIB /助手/ upda te / castArrayFilters.js:59:37)
at _castArrayFilters(/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/query.js:1739: 5)
at model.Query.Query._findAndModify(/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/query.js:3205:3)在model.Query上
。 (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/query.js:2830:8)
at model.Query._wrappedThunk [as _findOneAndUpdate] (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/helpers/query/wrapThunk.js:16:8)
at process.nextTick(/ Users / user / Desktop / Projects / ParentsPlus / ParentsPlusRepo / parents-plus-back-end / node_modules / kareem / index.js:369:33)
at _combinedTickCallback(internal / process / next_tick.js:132:7 )
at process._tickCallback(internal / process / next_tick.js:181:9)
"TypeError: Cannot read property 'castForQuery' of undefined at castArrayFilters (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/helpers/update/castArrayFilters.js:59:37) at _castArrayFilters (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/query.js:1739:5) at model.Query.Query._findAndModify (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/query.js:3205:3) at model.Query. (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/query.js:2830:8) at model.Query._wrappedThunk [as _findOneAndUpdate] (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/helpers/query/wrapThunk.js:16:8) at process.nextTick (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/kareem/index.js:369:33) at _combinedTickCallback (internal/process/next_tick.js:132:7) at process._tickCallback (internal/process/next_tick.js:181:9)"
推荐答案
我认为自版本 5.4.4
或可能是另一个以前版本以来有一个错误。据报道这里。目前我通过将mongoose版本下载到 5.3来解决它。 15
I think there is a bug since version 5.4.4
or maybe another previous version. It was reported here. For the moment I solved it by downloading the mongoose version to 5.3.15
.
这篇关于无法在Node.js中的castArrayFilters中读取未定义的属性'castForQuery'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!