MongoDB复合物分阶段查询,结果不同



我正在尝试为我们的产品团队找到查询语言,因此他们可以根据集合的复杂查询来创建"红色列"。由于他们不熟悉代码,所以我尝试查看JSONIQ解决方案,但看来它是未经维护的,找不到简单的解决方案。

所以它们是一个简单的选择?Mongo可以"阶段"查询完成以下示例(如果是,如何?(

itemCount = number of total contributionItems if itemCount>5 foreach item if (number of items with the same party)/itemCount>0.8 save that party as party1 PH1=party1 for each contributionItem if (contributionItem.party != party1) add item to array. PH2=array[item.party]

jsoniq作为一种语言,是活着的和维护的。该规范不经常更新,因为它是稳定的。语言网站上有一些可用的实现,这些实现可能会随着时间而变化(我不确定当前是否有专门支持MongoDB(。

据我了解,您的查询的JSONIQ版本看起来像:

let $contribution-items := collection("contribution-items")
let $count := count($contribution-items)
where $count gt 5
let $party1 :=
    for $item in $contribution-items
    group by $party := $item.party
    where count($item) gt (0.8 * $count)
    return $party
where exists($party1)
return [ $contribution-items[$$.party ne $party1] ]

最新更新