Skip to content

Instantly share code, notes, and snippets.

@abhay
Created Mar 5, 2010
Embed
What would you like to do?
query = new Riak.Query();
query.input = 'people';
query.addMapper(function(value, keyData, arg) {
if (value.age && value.age < 18) {
return [value];
} else {
return [];
}
});
query.addMapper(function(value, keyData, arg) {
if (value.address && value.address.state) {
return [{value.address.state: 1}];
}
else {
return [];
}
});
query.addReducer(function(acc, item) {
for (state in item) {
if (acc[state]) {
acc[state] += item[state];
} else {
acc[state] = item[state]
}
}
return acc;
});
new Riak.Query(
input: 'people',
mappers: [
function(value, keyData, arg) {
if (value.age && value.age < 18) {
return [value];
} else {
return [];
}
},
function(value, keyData, arg) {
if (value.address && value.address.state) {
return [{value.address.state: 1}];
}
else {
return [];
}
}
],
reducers: [
function(acc, item) {
for (state in item) {
if (acc[state]) {
acc[state] += item[state];
} else {
acc[state] = item[state]
}
}
return acc;
}
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment