Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get random records form mongodb via map/reduce
function(k, v) {
return v.a ? v.a.map(function(x) {
return x.k
}) : [v.k]
}
function(k,v){return v.a?v.a.map(function(x){return x.k}):[v.k]}
function() {
emit(0, {k: this, v: Math.random()})
}
function(){emit(0,{k:this,v:Math.random()})}
function(k, v) {
var a = []
v.forEach(function(x) {
a = a.concat(x.a ? x.a : x)
})
return {a:a.sort(function(a, b) {
return a.v - b.v;
}).slice(0, 3 /*how many records you want*/)};
}
function(k,v){var a=[];v.forEach(function(x){a=a.concat(x.a?x.a:x)});return{a:a.sort(function(a,b){return a.v-b.v}).slice(0,3)}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.