English 中文(简体)
• 如何用管道对评估养蜂和公投厅的一系列物体进行对比
原标题:How to do a $lookup with pipeline doing matches on an array of objects evaluating a boolean and OID

I m与mongo和Im一起工作,目前面临我能够指出的问题。

我们有2个收藏品,我们正对头1个收集材料进行汇总,然后对第二套材料进行研究。

这是收集形式的例子。

// document item in collection Items
let item = {
   ...
   category: ObjectId( A )
}

// document partner in collection Partners
let partner = {
   ...
   supportedCategories: [{ category: ObjectId( A ), active: true }, ...]
}

这样做的用意是获得所有信标系统,给它们增加一个称为合作伙伴的领域,列出在所支持的汇票阵列内拥有一个配对类别和正国旗的伙伴。

现在,我们没有管道,就有了这笔 $,这正在使所有与“国际发展法”类相匹配的合作伙伴重新受益,但并未考虑到其他ool。

{
  $lookup: {
    from:  partners ,
    localField:  category ,
    foreignField:  supportedCategories.category ,
    as:  joinedPartners ,
  },
},

现在,我有麻烦地把这比起积极的东西增加。 我曾尝试过许多不同的事情,但没有成功。

{
  $lookup: {
    from: "partners",
    let: {
      mycat: "$category"
    },
    pipeline: [
      {
        $match: {
          supportedCategories: {
            $elemMatch: {
              category:  $$mycat ,
              active: true
            }
          }
        },
      },
    ],
    as: "joinedPartners"
  }
}

因此,在最后的一次尝试中,失败的实际上是类比:现值:实值工作罚款,如果我以硬编码价值取代元件,如<代码>:目标类别(65282c77bcad9b5380acfa28 ),则一切都完全正确。 因此,我认为,我可以列举的是如何使用“让图”中储存的价值。

这对我做错做什么或我在这里失踪有何影响?

数种不同的备选方案,有预测值,从中得起,美元 能够使其与两个领域相匹配。

问题回答

在您的<条码> $/条码>下线上,您可使用<条码><> > 00美元/代码>,将阵列条目绘制成一阵列,同时进行情况检查。 然后,使用<代码>$anyElementTrue过滤结果阵列。

db.items.aggregate([
  {
    "$match": {
      "category": "A"
    }
  },
  {
    "$lookup": {
      "from": "partners",
      "let": {
        "mycat": "$category"
      },
      "pipeline": [
        {
          "$match": {
            "$expr": {
              "$anyElementTrue": {
                "$map": {
                  "input": "$supportedCategories",
                  "as": "cat",
                  "in": {
                    $and: [
                      {
                        $eq: [
                          "$$cat.category",
                          "$$mycat"
                        ]
                      },
                      {
                        $eq: [
                          true,
                          "$$cat.active"
                        ]
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      ],
      as: "joinedPartners"
    }
  }
])

Mongo 游乐场





相关问题
Sitecore not resolving rich text editor URLS in page renders

We re having issues inserting links into rich text in Sitecore 6.1.0. When a link to a sitecore item is inserted, it is outputted as: http://domain/~/link.aspx?_id=8A035DC067A64E2CBBE2662F6DB53BC5&...

Should I parse git status or use gitsharp?

I d like to integrate git into production pipeline to stage 3dsmax files. While it is alright to work with git through TortoiseGit, I d like to communicate with it from the Maxscript to add custom ...

XNA: Dynamic content loading without Game Studio installed?

I d like to enable my game to load content (such as a model, a jpg file, etc.) during run-time and display them. I looked at the sample on XNA website (http://creators.xna.com/en-US/sample/...

C# Stream Design Question

I have an appliction right now that is a pipeline design. In one the first stage it reads some data and files into a Stream. There are some intermediate stages that do stuff to the stream of data. And ...

热门标签