{
"name": "John",
"mark": 70,
"id": 1,
"course": "Mathematics"
},
{
"name": "John",
"mark": 90,
"id": 2,
"course": "English"
}
Suppose we want to aggregate all John's marks in an object like
{
Mathematics: 70,
English: 90,
... // <course>: <mark>
}
r.table("marks").filter({student: "John"}).map(function(mark) {
return r.object(mark("course"), mark("mark")) // return { mathematics: 70 }
}).reduce(function(left, right) {
return left.merge(right);
})