不能使用“in”运算符在 true 中搜索“transform”

问题描述

在我的评论模型中填充用户和电影字段时出现此错误错误Cannot use 'in' operator to search for 'transform' in true

reviewSchema.pre(/^find/,function(next){
    this.populate({  
        path:'user',select:'name'
    }).populate({
        path:'movie',select:'name'
    })
    next();
})

填充代码仅适用于 user 而不适用于 movie 即如果我删除了电影的填充代码,那么我会在输出中得到用户的填充结果 但对于上面的代码,它给出了错误 我的评论架构代码

const reviewSchema=new mongoose.Schema({
    review:{
        type:String,required:['true','blank space not allowed'],trim:true
    },rating:{
        type:Number,max:5,min:1
    },user:{
        type:mongoose.Schema.ObjectId,ref:'movieUsers',required:[true,'review must have a user']
    },movie:{
        type:mongoose.Schema.ObjectId,ref:'movies','review must belong to a movie']
    }
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)