How To Install RethinkDB On Ubuntu?
How To Install RethinkDB On Ubuntu?
What is RethinkDB?
RethinkDB is an open source, document based NoSQL database that stores the information in JSON format.
Features of RethinkDB
- It is easy to use, has a rich data model and supports extremely flexible querying capabilities.
- RethinkDB adds a modern qsuery language called ReQL, a massively parallel distributed infrastructure, support for distributed joins and subqueries (that lacks in other NoSQL databases), and has an incredible web interface.
- Sharding and replication can be done in a few clicks using the web interface.
- It inverts the traditional database architecture by revealing an exciting new access model. Instead of polling for changes, we can tell RethinkDB to continuously push updated query results to applications in real-time and reduces the time and efforts which are necessary to build scalable real-time applications.
- In the recent versions of RethinkDB, support for multiple user accounts and permissions are added.
How to Install RethinkDB on Ubuntu
- Install RethinkDB server
- For Ubuntu, you can install the package for RethinkDB by executing the following commands:
$ source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list $ wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add - $ sudo apt-get update $ sudo apt-get install rethinkdb
- For other platforms, follow instructions given at https://rethinkdb.com/docs/install/
- For Ubuntu, you can install the package for RethinkDB by executing the following commands:
- Start RethinkDB server
- Start RethinkDB server by executing the following command
$ rethinkdb
- RethinkDB server will listen to client connections on port 28015, cluster connections on port 29015 and also start a web interface at port 8080.
- Start RethinkDB server by executing the following command
- Access web interface
- You can navigate to http://localhost:8080 to access the web interface of RethinkDB.
- Install RethinkDB client
- There are a number of client drivers available for popular programming languages.
- For JavaScript driver with Node installed, you can install the RethinkDB client driver by running the following command,
$ npm install rethinkdb
- For other clients, follow the instructions given at https://www.rethinkdb.com/docs/install-drivers/
ReQL query language
- ReQL is a query language to execute queries in RethinkDB using JSON documents.
- Each host programming language driver (currently Python, Ruby, Java, and JavaScript) implements a custom, tightly integrated domain-specific language.
- ReQL is a unified chainable query language supporting:
- CRUD operations
- Aggregations including map-reduce
- Joins
- Sub-queries
- Changefeeds that allow clients to receive changes on a table, a single document, or even the results from a specific query as they happen.
- Examples
- Let’s say, we have a RethinkDB database called ‘github’ containing a collection of GitHub repositories. We can extract particular information by executing the following ReQL queries
- Get all repositories:
r.db('github').table('repos').run();
- Insert a document:
r.db('github').table('repos') .insert({ 'name': 'rails', 'forks': 17133, 'watchers': 2637 }) .run();
- Get all repositories:
- Let’s say, we have a RethinkDB database called ‘github’ containing a collection of GitHub repositories. We can extract particular information by executing the following ReQL queries
-
-
- Get information for ‘rails’ repository:
r.db('github').table('repos') .filter({ 'name': 'rails' }) .run();
- Get all repositories ordered by their popularity (or number of watchers)
r.db('github').table('repos') .orderBy(r.desc('watchers')) .run();
- Get information for ‘rails’ repository:
-
RethinkDB data model
- RethinkDB supports basic data types including numbers, strings, boolean values, objects, arrays, and the null value.
- In addition, it also stores RethinkDB-specific data types including tables, streams, selections, binary objects (like a file or an image), time objects (with millisecond precision), geometry data types (like points, lines, and polygons)
RethinkDB NodeJS API
- Following code snippet represents a connection of RethinkDB JavaScript client with the server.
r = require(‘rethinkdb’); r.connect({ host: 'localhost', port: 28015 }, function(error, conn) { if(error) { throw error; } else { console.log(conn); } });
- First, we need to import the ‘rethinkdb’ module. Then we can use the ‘connect’ API to connect the client to the server at port 28015. This will return a connection object ‘conn’ that we can use further to query the database.
Deployment
- RethinkDB can be easily be deployed on cloud services such as Compose and Amazon Web Services.