Created
January 23, 2014 18:47
-
-
Save baruch/8584442 to your computer and use it in GitHub Desktop.
ReQL: For a field get in one query the count, min, max and sample entries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db('mydb').table('disk').withFields('glist').groupedMapReduce( | |
function(x) { return x }, | |
function(x) { return 1 }, | |
function(x,y) { return 1 } | |
) | |
.map(function (x) { return x('group')('glist') }) | |
.reduce(function(x,y) { return | |
{ | |
count: x('count').add(1), | |
val: x('val').union([y]).sample(10), | |
min: r.branch(x('min'), r.branch(x('min').lt(y), x('min'), y), y), | |
max: r.branch(x('max'), r.branch(x('max').gt(y), x('max'), y), y) | |
}}, | |
{count: 0, val: [], min: null, max:null}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment