Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Getting Started with RethinkDB
Getting Started with RethinkDB

Getting Started with RethinkDB: Absorb the knowledge required to utilize, manage, and deploy

eBook
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Getting Started with RethinkDB

Chapter 2. The ReQL Query Language

RethinkDB is queried using ReQL—a custom query language designed to be powerful and intuitive. ReQL provides a clear syntax that can be used to manipulate JSON documents in the database. This chapter will introduce you to the most common ReQL queries. More advanced use cases will be covered in the Chapter 4, Performance Tuning and Advanced Queries.

This chapter also covers the basics of moving data in and out of the database by creating tables and populating them with JSON documents.

In this chapter, you will learn the following:

  • Creating a database
  • Creating new tables
  • Adding, updating, and removing documents
  • Querying the database and manipulating results

Before we start querying the database, let's take a closer look at how a document database works, focusing on RethinkDB's data structure—JSON documents.

Documents

Documents are RethinkDB's main data structure. To fully understand and use the database, you need to think in documents. In this chapter, we're going to go through the lifecycle of designing and saving a document in RethinkDB. We'll follow up by reading, aggregating, and querying documents using ReQL. In the previous section, you'll see how RethinkDB can also manipulate and transform query results.

Documents are self-contained units of data. In relational databases, you might have heard the term record to describe something similar. When you insert some information into a database, the data is usually made up of small native types such as integers and strings. Documents are the first level of abstraction over these native types. They give primitive data some structure and logically group it. Additionally, RethinkDB documents support more complex data types such as binary data, dates and times, and arrays.

Suppose we want to store the age of a person in the...

Introducing ReQL

A database is only as good as its query language.

For a developer, the query language is basically an interface to the database; however, it's disappointing to say that most of the existing query languages are easy to use or powerful but not both. Thankfully, with ReQL, you get the best of both worlds as the query language is intuitive but very powerful at the same time.

An explicit query language

Instead of writing complex, SQL-like queries, ReQL lets you write practical, simple queries. One of its best features is that ReQL can be considered an explicit query language. The way in which you approach RethinkDB is not only simple and intuitive, but it also gives you a good idea of how the query is being executed within the database, giving you the right balance of abstraction.

Let's look at an example query:

r.table('users').filter({ name: 'Alex' }).orderBy(r.desc('age'))

In this simple query, we get all the users with the name Alex ordered...

Inserting data

Before inserting documents into the database, we must create a table to hold our data. We can do this using the tableCreate() command that takes the table name as an argument. Let's create a table called people by running the following query:

r.db('test').tableCreate('people')

This query assumes you have a database called test and creates the people table within this database. If the query is successful, you will get an output similar to this:

{
  "config_changes":[
    {
      "new_val":{
        "db":"test",
        "durability":"hard",
        "id":"a29447ca-1587-4b8c-86db-a7b3d5198519",
        "name":"people",
        "primary_key":"id",
        "shards":[
          {
            "primary_replica":"rethinkdb1",
            "replicas":[
              "rethinkdb1"
            ]
 ...

Reading data

This section looks at querying the database in detail. Querying returns a subset of documents in a table—from no documents at all to the entire table. Which documents get returned depends on what type of filtering we do in the query. The absence of the filter() command matches everything in a table.

One of the most common queries that you might want to run is reading all documents from a table. While this may not be a very efficient query when the table contains thousands of entries as it requires scanning the entire table, it can definitely be useful for debugging purposes.

We can read the entire table from the database just by selecting the database and an appropriate table as follows:

r.db('test').table('people')

If you've been running the queries from the previous sections, the result will contain three documents:

Reading data

Note

For a more concise result view, you can choose the "table view" from the Data Explorer.

Filtering results

We can use the...

Updating data

Once a document is stored in a RethinkDB table, it can be changed using the update() command. This command accepts a JSON document or ReQL expression as input and returns the number of updated documents.

Updating existing attributes

Updating a document can alter one or more attributes already present within the document itself, or can add a new attribute. Let's pretend we made a mistake inserting Amy's year of birth and we want to change the value from 1998 to 1997; we can update the related document using the following query:

r.table('people').get('f1664276-1aad-4998-8240-410a82883115').update({"yearOfBirth": 1997})

First, we get the correct document using its primary key. Then we call the update() command, passing it a JSON document that contains the changes. In this case, the change is as follows:

({"yearOfBirth": 1997}

If we now query the database searching for Amy's document, we can see that year of birth has, in fact,...

Documents


Documents are RethinkDB's main data structure. To fully understand and use the database, you need to think in documents. In this chapter, we're going to go through the lifecycle of designing and saving a document in RethinkDB. We'll follow up by reading, aggregating, and querying documents using ReQL. In the previous section, you'll see how RethinkDB can also manipulate and transform query results.

Documents are self-contained units of data. In relational databases, you might have heard the term record to describe something similar. When you insert some information into a database, the data is usually made up of small native types such as integers and strings. Documents are the first level of abstraction over these native types. They give primitive data some structure and logically group it. Additionally, RethinkDB documents support more complex data types such as binary data, dates and times, and arrays.

Suppose we want to store the age of a person in the database. This data might...

Introducing ReQL


A database is only as good as its query language.

For a developer, the query language is basically an interface to the database; however, it's disappointing to say that most of the existing query languages are easy to use or powerful but not both. Thankfully, with ReQL, you get the best of both worlds as the query language is intuitive but very powerful at the same time.

An explicit query language

Instead of writing complex, SQL-like queries, ReQL lets you write practical, simple queries. One of its best features is that ReQL can be considered an explicit query language. The way in which you approach RethinkDB is not only simple and intuitive, but it also gives you a good idea of how the query is being executed within the database, giving you the right balance of abstraction.

Let's look at an example query:

r.table('users').filter({ name: 'Alex' }).orderBy(r.desc('age'))

In this simple query, we get all the users with the name Alex ordered in descending order by age. If we were...

Left arrow icon Right arrow icon

Key benefits

  • Make the most of this open source, scalable database—RethinkDB —to ease the construction of web applications
  • Run powerful queries using ReQL, which is the most convenient language to manipulate JSON documents with
  • Develop fully-fledged real-time web apps using Node.js and RethinkDB

Description

RethinkDB is a high-performance document-oriented database with a unique set of features. This increasingly popular NoSQL database is used to develop real-time web applications and, together with Node.js, it can be used to easily deploy them to the cloud with very little difficulty. Getting Started with RethinkDB is designed to get you working with RethinkDB as quickly as possible. Starting with the installation and configuration process, you will learn how to start importing data into the database and run simple queries using the intuitive ReQL query language. After successfully running a few simple queries, you will be introduced to other topics such as clustering and sharding. You will get to know how to set up a cluster of RethinkDB nodes and spread database load across multiple machines. We will then move on to advanced queries and optimization techniques. You will discover how to work with RethinkDB from a Node.js environment and find out all about deployment techniques. Finally, we’ll finish by working on a fully-fledged example that uses the Node.js framework and advanced features such as Changefeeds to develop a real-time web application.

Who is this book for?

Getting Started with RethinkDB is ideal for developers who are new to RethinkDB and need a practical understanding to start working with it. No previous knowledge of database programming is required, although a basic knowledge of JavaScript or Node.js would be helpful.

What you will learn

  • Download and install the database on your system
  • Configure RethinkDB's settings and start using the web interface
  • Import data into RethinkDB
  • Run queries using the ReQL language
  • Create shards, replicas, and RethinkDB clusters
  • Use an index to improve database performance
  • Get to know all the RethinkDB deployment techniques

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 17, 2016
Length: 176 pages
Edition : 1st
Language : English
ISBN-13 : 9781785884467
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 17, 2016
Length: 176 pages
Edition : 1st
Language : English
ISBN-13 : 9781785884467
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 103.97
Mastering RethinkDB
€36.99
Principles of Data Science
€36.99
Getting Started with RethinkDB
€29.99
Total 103.97 Stars icon
Banner background image

Table of Contents

8 Chapters
1. Introducing RethinkDB Chevron down icon Chevron up icon
2. The ReQL Query Language Chevron down icon Chevron up icon
3. Clustering, Sharding, and Replication Chevron down icon Chevron up icon
4. Performance Tuning and Advanced Queries Chevron down icon Chevron up icon
5. Programming RethinkDB in Node.js Chevron down icon Chevron up icon
6. RethinkDB Administration and Deployment Chevron down icon Chevron up icon
7. Developing Real-Time Web Applications Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(1 Ratings)
5 star 0%
4 star 100%
3 star 0%
2 star 0%
1 star 0%
JJ Jan 08, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Lovely book bringing you up to speed on RethinkDB. Concise and to-the-point.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.