Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rolled together a startup of rethinkdb on OS X and a couple of fixes from a tutorial
This tutorial had a few bugs in it:
getting started on Mac OS X...
The first few items are run in the terminal, and while I'm sure there are other ways to load the data,
I just went with what was in the tutorial, which included using the Python driver for Rethinkdb via pip.
After the last command in here, things seemed to just work... so I pass you back to the tutorial page.
brew update
brew install rethinkdb
(start it up!)
# To get the data for the tutorial
sudo easy_install pip
sudo pip install rethinkdb
rethinkdb import -c localhost:28015 --table test.input_polls --pkey uuid -f input_polls.json --format json
rethinkdb import -c localhost:28015 --table test.county_stats --pkey uuid -f county_stats.json --format json
#in javascript using the data explorer (http://localhost:8080/#dataexplorer)
.group("id") // We group the table by `id`, which is the state name.
.pluck('Dem', 'GOP') // We pluck out the poll results we care about.
.merge({polls: 1}) // And finally, we add an extra field `polls: 1` to each row.
.reduce(function(left, right){
// We reduce over the polls, adding up the results and keeping
// track of the total number of polls.
return {
Dem: left("Dem").add(right("Dem")),
GOP: left("GOP").add(right("GOP")),
polls: left("polls").add(right("polls"))
// We ungroup and divide the fields `Dem` and `GOP` for each state
// by the number of polls to get the average result per state.
return {
Dem: state("reduction")("Dem").div(state("reduction")("polls")),
GOP: state("reduction")("GOP").div(state("reduction")("polls")),
polls: state("reduction")("polls"),
id: state("group")
#etc as in the tutorial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment