Skip to content

Instantly share code, notes, and snippets.

@baruch
Created January 23, 2014 18:47
Show Gist options
  • Save baruch/8584442 to your computer and use it in GitHub Desktop.
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
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