本文介绍了无法在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:

这是架构:

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);
    })

这是例外


推荐答案

我认为自版本 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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:12