Created
September 30, 2010 18:28
-
-
Save frank06/605060 to your computer and use it in GitHub Desktop.
This file contains 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
db = require('riak-js').getClient() | |
db | |
.add([['catalogs', 'politics']]) | |
.link({ bucket: 'books', keep: false }) | |
.map(function(value) { | |
// ejsLog('/tmp/mapreduce', JSON.stringify(value)); | |
value = Riak.mapValuesJson(value)[0]; | |
return [ | |
{ | |
id: value.id, | |
title: value.title, | |
author: value.author | |
} | |
]; | |
}) | |
.reduce(function(values) { | |
return values.sort(function(a, b) { return a.title < b.title ? -1 : 1; }); | |
}) | |
.run() |
This should work:
.reduce(function(values, args) {
// use args.start & args.limit
}, { start: 0, limit: 10 })
Thank you Frank, It works!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi frank. Can u please help me?
I toke your code and added a slice after the sort:
var start = 0;
var limit = 10;
....
....
.reduce(function(values) {
return values.sort(function(a, b) { return a.title < b.title ? -1 : 1; })
.slice(start,limit);
})
but It doesnt work. I guess couse on MapReduce runtime (at riak node) start and limit are undefined right?
Do you know how to pass vars into a reduce?
Thank you.
Ale