无法在Node.js中的castArrayFilters中读取未定义的属性'castForQuery'

编程入门 行业动态 更新时间:2024-10-28 16:28:45
本文介绍了无法在Node.js中的castArrayFilters中读取未定义的属性'castForQuery'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 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'

本文发布于:2023-11-28 09:17:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641817.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   未定义   js   Node   castArrayFilters

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!