猫鼬使用同一集合中的两个填充物来查找

问题描述

我试图了解如何从同一集合中同时填充两个引用。 我有这些模型:

const bookingSchema = new Schema( {

    created_at: { 
        type: String,default: moment().format('llll')
    },// When service start in timestams seconds
    date: { 
        type: Number
    },package: {
        type: Schema.Types.ObjectId,ref: 'Package',required: [ true,'A reference to a package must exist']
    },status: {
        type: String // ['pending','confirmed','finished']
    },});

const packageSchema = new Schema( {


    title: {
        type: String
    },profile: {
        type: Schema.Types.ObjectId,ref: 'Profile','A reference to a profile must exist']
    },service: {
        type: Schema.Types.ObjectId,ref: 'Service','A reference to a service must exist']
    }

]


  
});

这是查询,我只能获取配置文件信息,但是服务始终为NULL,但是每个Package都有一个服务。 可能我在语法上犯了错误吗?如果看到的话,用我要附加到查询结果,配置文件和服务的引用填充一个数组,配置文件正确无误,问题出在服务上。

 return Booking.find( {'package': {$in: ids}} )
            .populate({
                path: 'package',model: 'Package',match: {'profile' : { $exists: true}},select : 'profile title service language',populate : [
                    {
                        path : 'service',model: 'Service',select : '_id name'
                    },{
                    path : 'profile',model: 'Profile',select : '_id name',populate: { 
                        path: 'user',model: 'User',select: 'role'
                    
                    }
                  }
                
              ]
                
            })
       
            .sort( { date: -1 } )
            .exec();

解决方法

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

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

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...