猫鼬$ aggregate $ lookup不返回数据

时间:2019-06-21 10:44:17

标签: javascript node.js mongodb express mongoose

我有以下代码

Users.aggregate([{
            $match: dt //working fine
        }, {
            $lookup: { //not working returns []
                from: "points",
                localField: "_id", //field in user collection
                foreignField: "user", //field in points collection
                as: "points"
            }
        }, {
            $lookup: {
                from: "orders", //not working returns []
                localField: "_id", //field in user collection
                foreignField: "user_id", //field in orders collection
                as: "orders"
            }
        }], (err, data) => {
            return res.status(200).json({
                message: "success",
                data: data ? data : [],
                status: true
            })
        })

点和订单集合中有16条记录,但始终返回空数组。 我找不到问题。请帮忙。 在定点和订单集合中添加了用户ID。 还有其他方法可以通过用户表在这些集合中查找数据吗?除了填充,我什么都没找到。

  

MongoDB服务器版本:3.6.9

     

“猫鼬”:“ ^ 5.3.4”

0 个答案:

没有答案
相关问题