What is RethinkDB?
• Open source database for building
realtime web applications
• NoSQL database that
stores schemaless JSON documents
• Distributed database that is easy to
scale
Slide 5
Slide 5 text
Built for Realtime Apps
• Subscribe to change notifications
from database queries
• No more polling — the database
pushes changes to your app
• Reduce the amount of plumbing
needed to stream live updates
Additional ReQL Features
• Date and time functions for time
data
• Support for storing binary objects
• r.http allows you to execute http
requests from the database
Slide 18
Slide 18 text
Realtime Updates
Working with Changefeeds
Slide 19
Slide 19 text
Subscribe to change notifications
on database queries
Changefeeds
Slide 20
Slide 20 text
r.table("users").changes()
Track changes on the users table
Changefeeds
Changefeeds
r.table("players")
.orderBy({index: r.desc("score")})
.limit(3).changes()
Track top three players by score
Chain the changes command
to an actual ReQL query:
Slide 25
Slide 25 text
Using Changefeeds
Slide 26
Slide 26 text
Advanced ReQL
Geospatial Features
Slide 27
Slide 27 text
Introduction to Geospatial
• Geospatial queries are integrated
into ReQL
• With changefeeds, you can listen
to changes in your geospatial data
Question
Which counties in the USA
have the highest density of
restaurants?
Slide 37
Slide 37 text
Demo
Slide 38
Slide 38 text
County + Restaurant data
Slide 39
Slide 39 text
Restaurants in county query
return r.table("counties")
// 1. Get number of restaurants
.merge(...)
// 2. Calculate restaurant density
.merge(...)
Get restaurant density
Slide 40
Slide 40 text
Restaurants in county query
Get all counties
return r.table("counties")
// 1. Get number of restaurants
.merge(...)
// 2. Calculate restaurant density
.merge(...)
Slide 41
Slide 41 text
Restaurants in county query
return r.table("counties")
// 1. Get number of restaurants
.merge({
restaurants: // ..
})
// 2. Calculate restaurant density
.merge(...)
Merge a property into county
Slide 42
Slide 42 text
Restaurants in county query
return r.table("counties")
// 1. Get number of restaurants
.merge({
restaurants: r.table('restaurants')
.getIntersecting(row('geometry'),
{ index: 'geometry' })
.count()
})
// 2. Calculate restaurant density
.merge(...)
Get number of restaurants in county
Slide 43
Slide 43 text
Restaurants in county query
Get restaurants table
return r.table("counties")
// 1. Get number of restaurants
.merge({
restaurants: r.table('restaurants')
.getIntersecting(row('geometry'),
{ index: 'geometry' })
.count()
})
// 2. Calculate restaurant density
.merge(...)
Slide 44
Slide 44 text
Restaurants in county query
Get intersecting geometries
return r.table("counties")
// 1. Get number of restaurants
.merge({
restaurants: r.table('restaurants')
.getIntersecting(row('geometry'),
{ index: 'geometry' })
.count()
})
// 2. Calculate restaurant density
.merge(...)
Slide 45
Slide 45 text
Restaurants in county query
Count intersecting geometries
return r.table("counties")
// 1. Get number of restaurants
.merge({
restaurants: r.table('restaurants')
.getIntersecting(row('geometry'),
{ index: 'geometry' })
.count()
})
// 2. Calculate restaurant density
.merge(...)
Slide 46
Slide 46 text
Restaurants in county query
return r.table("counties")
// 1. Get number of restaurants
.merge(...)
// 2. Calculate restaurant density
.merge({
stat: row('restaurants').div(row('area'))
})
Add new `stat` property
Slide 47
Slide 47 text
Restaurants in county query
return r.table("counties")
// 1. Get number of restaurants
.merge(...)
// 2. Calculate restaurant density
.merge({
stat: row('restaurants').div(row('area'))
})
Divide `restaurants` by `area`
Slide 48
Slide 48 text
Processed data
Slide 49
Slide 49 text
Client/ArcGIS
• Data is queried and sent through a
WebSocket connection
• Polygon geometry is converted into
ArcGIS Graphic and added to map
• Color (Symbol) is applied
dynamically based on max
Slide 50
Slide 50 text
Summary
• ReQL allows for complex
geospatial queries
• RethinkDB makes building
realtime applications a lot easier