Skip to content

Instantly share code, notes, and snippets.

@frank06
Created September 30, 2010 18:28
Show Gist options
  • Save frank06/605060 to your computer and use it in GitHub Desktop.
Save frank06/605060 to your computer and use it in GitHub Desktop.
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()
@alejamp
Copy link

alejamp commented Oct 25, 2011

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

@frank06
Copy link
Author

frank06 commented Oct 25, 2011

This should work:

.reduce(function(values, args) {
  // use args.start & args.limit
}, { start: 0, limit: 10 })

@alejamp
Copy link

alejamp commented Oct 25, 2011

Thank you Frank, It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment