简体   繁体   English

查找管道内的 ObjectId 匹配无法正常工作

[英]ObjectId match inside lookup pipeline doesn't work in normal way

The issue part is { $match: { contentId: "$$content_id" }} inside pipeline.问题部分是管道内的{ $match: { contentId: "$$content_id" }} It returns a empty array.它返回一个空数组。 but when I change it like below, it works fine.但是当我像下面这样改变它时,它工作正常。 This is a stage object of my aggregation pipeline.这是我的聚合管道的一个阶段 object。 What is the issue with the first?第一个有什么问题? Simple match is designed not to work in lookup pipeline when let variable is an objectId?当让变量是objectId时,简单匹配被设计为不适用于查找管道? Thank you for your time.感谢您的时间。

const contentReactionLookUp = (user_id) =>  { 
    return {
        $lookup: {
            from: "contentreactions",
            let: { content_id: "$_id" },
            pipeline: [
                { $match:
                     { $expr:


                                     { $eq: [ "$contentId", "$$content_id" ] },


                     }
                },
                //{ $match: { contentId: "$$content_id" }}, it doenst' work! 
            ],
            as: "userReaction"
        },
    }
}

https://docs.mongodb.com/manual/meta/aggregation-quick-reference/#aggregation-expressions I found my solution here. https://docs.mongodb.com/manual/meta/aggregation-quick-reference/#aggregation-expressions我在这里找到了我的解决方案。 mongo aggregation simple match doesn't work in case its passed value is field path. mongo 聚合简单匹配在其传递的值是字段路径的情况下不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM