如何将let与猫鼬js的导入模型一起使用管道

问题描述 投票:0回答:1

我尝试对猫鼬进行查询,即即时消息使用带$ let和$ pipeline的聚合,但是我无法引用我的方案模型的字段,查询返回未定义的值。模式的集合是导入文件。

const mongoose = require('mongoose');
const BASCULE  = require('../models/BASCULE');
const USER  = require('../models/USER');
const USER_BASC  = require('../models/USER_BASC');
USER_BASC.aggregate([
        {
            $lookup:{ 
                from: USER.collection.name, 
                let: { XXX: 'ID_USER' }, 
                pipeline: [
                { $match: { $expr: { $and: [ {$eq: [ "$DISABILITY", 'false'] }, 
                                             {$eq: [ "$ID", "$$XXX" ] } ] } }

                },
                {$project: { _id: 0 } }],

                as: 'INFO_USER' 
            },
        },
        {
            $match:{
                ID_BASC: req.params.id_0
            }
        },
        {
            $project: { _id: 0 } 
        }

]
mongodb mongoose let
1个回答
0
投票
在用于aggragate功能的mongoose框架中,与id匹配时,由于链接中提到的原因,您不得不提到它是mongodb对象的id。
© www.soinside.com 2019 - 2024. All rights reserved.