Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RethinkDB Primer
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Marcelo Alves
April 09, 2015
Programming
170
2
Share
RethinkDB Primer
A short introduction to RethinkDB
Marcelo Alves
April 09, 2015
Other Decks in Programming
See All in Programming
柔軟なPDFレイアウトエディタを支える型システム設計 — Discriminated UnionとConditional Typeの実践
minako__ph
4
1.2k
誰も頼んでない機能を出荷した話
zekutax
0
150
Inside Stream API
skrb
1
450
さぁV100、メモリをお食べ・・・
nilpe
0
120
色即是空、空即是色、データサイエンス
kamoneggi
1
250
Modding RubyKaigi for Myself
yui_knk
0
830
Oxlintのカスタムルールの現況
syumai
5
920
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
0
250
[KCD Czech] eBPF Meets the GPU: Future of AI Infra Observability
doniacld
0
130
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
400
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
100
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
140
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
150
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
The Invisible Side of Design
smashingmag
302
52k
How GitHub (no longer) Works
holman
316
150k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
Designing Powerful Visuals for Engaging Learning
tmiket
1
390
The Curious Case for Waylosing
cassininazir
1
370
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
Crafting Experiences
bethany
1
160
Transcript
RethinkDB a primer
What is RethinkDB? An open-source distributed database built with .
"MongoDB with joins"
Features JSON data model Distributed joins, subqueries, aggregation and atomic
updates Hadoop-style map/reduce Friendly web and command-line administration tools Multi-datacenter replication and failover Sharding and replication Queries are automatically parallelized and distributed
Getting Started
Installation tyrion@kings-landing:~$ brew update tyrion@kings-landing:~$ brew install rethinkdb
Set Up tyrion@kings-landing:~$ rethinkdb
Web UI
Clustering tyrion@kings-landing:~$ rethinkdb create –d /tmp/db1 tyrion@kings-landing:~$ rethinkdb –j –d
/tmp/db1 --port-offset 1
Clustering
Clustering
Gem tyrion@kings-landing:~$ gem install rethinkdb [1] pry(main)> require "rethinkdb" [2]
pry(main)> include RethinkDB::Shortcuts [3] pry(main)> r.connect(host: 'localhost', database: 'marvel').repl()
Working with RethinkDB
Get All [1] pry(main)> r.table('characters').run
Get Document [1] pry(main)> r.table('characters').get(1).run
Filter [1] pry(main)> r.table('characters').filter({ age: 30 }).run
Update [1] pry(main)> r.table('characters').get(1).update({ age: 50}).run
Delete [1] pry(main)> r.table('characters').get(1).delete.run
ReQL
Principles 1. ReQL embeds into your programming language. 2. All
ReQL queries are chainable. 3. All queries execute on the server.
Embeds into your Language [1] pry(main)> require "rethinkdb" [2] pry(main)>
include RethinkDB::Shortcuts [3] pry(main)> r.connect(host: 'localhost', database: 'marvel').repl() [1] pry(main)> r.table('characters').get(1).delete.run
Chainable Queries [1] pry(main)> r.table('characters').run [2] pry(main)> r.table('characters').pluck('last_name').distinct().run [3] pry(main)>
r.table('characters').pluck('last_name').distinct().count().run
Server-Side Execution [1] pry(main)> query = r.table('characters').pluck('last_name').distinct [2] pry(main)> query.run
Examples
Filter + Contains [1] pry(main)> r.table('user').filter{|user| user['emails'].contains('
[email protected]
')}.run
Filter Dates [1] pry(main)> r.table("posts").filter{ |post| [2] pry(main)> post.during(r.time(2012, 1,
1, 'Z'), r.time(2013, 1, 1, 'Z')) [3] pry(main)> }.run
Filter + Pluck + Order + Limit [1] pry(main)> r.table('snippets').
[1] pry(main)* filter({lang: 'ruby'}). [1] pry(main)* pluck('id', 'title', 'created_at'). [1] pry(main)* order_by(r.desc('created_at')). [1] pry(main)* limit(10). [1] pry(main)* run()
Group + Merge [1] pry(main)> r.table('invoices').group( [1] pry(main)* [r.row['date'].year(), r.row['date'].month()]
[1] pry(main)* ).ungroup().merge( [1] pry(main)* {invoices: r.row['reduction'], month: r.row['group']} [1] pry(main)* ).without('reduction', 'group').order_by('month').run
Cool Features
Geospatial [1] pry(main)> point1 = r.point(-122.423246,37.779388) [2] pry(main)> point2 =
r.point(-117.220406,32.719464) [3] pry(main)> r.distance(point1, point2, {:unit => 'm'}).run [4] pry(main)> r.circle(point1, 2000).includes(point2).run
HTTP [1] pry(main)> r.table('comics').insert(r.http('http://foo.com/comics')).run
Changes [1] pry(main)> r.table('games').changes().run.each{|change| p change}
None