我正在尝试为我们的产品团队找到一种查询语言,因此他们可以根据集合的复杂查询创建“红旗”。 因为他们不熟悉代码,我试过看JsonIQ解决方案,但它似乎没有维护,也找不到MongoDB的简单解决方案。
所以他们是一个简单的选择?可以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]
答案 0 :(得分:0)
作为一种语言,JSONiq仍然存在并得到维护。规范不经常更新,因为它是稳定的。 language website上记录了一些可用的实现,这些实现可能会随时间而变化(我不确定当前是否有任何特定的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] ]