0

I'm trying to find a Query Language for our product team, so they can create "red-flags" based on complex queries of a collection. as they are not familiar with code, i've tried looking at JsonIQ solution but it seems it's un-maintained and couldn't find a simple solution to MongoDB.

So they a simple alternative? can mongo "stages" query accomplish something like the following example (if so, how?)

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]

Ran Landau
  • 55
  • 1
  • 6
  • it's not clear, can you add sample documents from your collection, and the expected output? – felix May 03 '17 at 10:11
  • Why unclear? Let's say i have an "items" table, which has different types. This is the begining // Pipeline [ // Stage 1 { $match: { "type": "ContributionItem", "searchId": 146 } }, // Stage 2 { $count: "count" }, // Stage 3 { $match: { count: { $gt: 5} } }, ] – Ran Landau May 03 '17 at 10:56

1 Answers1

0

JSONiq, as a language, is alive and maintained. The specification is not updated often because it is stable. There are a few implementations available documented on the language website and these may vary over time (I am unsure if any currently supports MongoDB specifically though).

A JSONiq version of your query, as I understand it, would look like:

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] ]
Ghislain Fourny
  • 6,971
  • 1
  • 30
  • 37