Py学习  »  MongoDB

MongoDB如何为嵌套数组生成投影过滤器

haha1 • 6 年前 • 1895 次点击  

这个问题已经有了答案:

我的JSON数据结构如下

"ArticleInfo": [{
    "InfArt": {
        "langs": [{
                "code": 1,
                "text": "Technische Information"
            },
            {
                "code": 4,
                "text": "Technical Information"
            },
            {
                "code": 6,
                "text": "Informations techniques"
            },
        ]
    }
}]

跟随 filter 我编写的shell命令的用法如下

db.article.aggregate(
    {
        $match: {
            "articleNumber": "123123"
        },
    },
    {
        $project: {
            'ArticleInfo.InfArt.langs': {
                $filter: {
                  input: "$ArticleInfo.InfArt.langs",
                  as: "item",
                  cond: { $eq: [ '$$item.code', 4 ] }
                }
            }
        }
    }
)

但是 $eq 看起来不像是工作,它给出了一个空列表

我想知道 langs 数组,我写错了吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39106
文章 [ 1 ]  |  最新文章 6 年前