O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting Started with RethinkDB

Book Description

Absorb the knowledge required to utilize, manage, and deploy RethinkDB using Node.js

About This Book

  • 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

Who This Book Is 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

In Detail

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.

Style and approach

This is a step-by-step book that provides a practical approach to RethinkDB programming, and is explained in a conversational, easy-to-follow style.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Getting Started with RethinkDB
    1. Table of Contents
    2. Getting Started with RethinkDB
    3. Credits
    4. About the Author
    5. Acknowledgement
    6. About the Reviewer
    7. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    9. 1. Introducing RethinkDB
      1. Rethinking the database
        1. Changefeeds
        2. Horizontal scalability
        3. Powerful query language
        4. Developer-oriented
        5. Document-oriented
        6. Lock-free architecture
        7. Immediate consistency
        8. Secondary indexes
        9. Distributed joins
      2. Installing RethinkDB
        1. Installing RethinkDB on Ubuntu/Debian Linux
        2. Installing RethinkDB on CentOS and Fedora
        3. Installing RethinkDB on OS X
          1. Installing RethinkDB using Homebrew
        4. Building RethinkDB from source
      3. Configuring RethinkDB
        1. Running as a daemon
        2. Creating a configuration file
      4. Starting RethinkDB
      5. Running a query
      6. Summary
    10. 2. The ReQL Query Language
      1. Documents
        1. Document databases
        2. JSON document format
          1. Keys
          2. Arrays
          3. Embedded documents
        3. Data modeling
      2. Introducing ReQL
        1. An explicit query language
        2. Building a query
      3. Inserting data
        1. Batch inserts
      4. Reading data
        1. Filtering results
        2. Manipulating results
      5. Updating data
        1. Updating existing attributes
        2. Adding new attributes
      6. Deleting data
        1. Removing all documents
        2. Deleting a table
        3. Deleting a database
      7. Summary
    11. 3. Clustering, Sharding, and Replication
      1. An introduction to scaling
        1. What kind of system is it?
        2. Scaling reads
        3. Scaling writes
        4. Scaling data
      2. Clustering RethinkDB
        1. Creating a cluster
        2. Adding a server to the cluster
        3. Running queries on the cluster
      3. Replication
        1. Adding a secondary replica
        2. Failover
      4. Sharding
        1. Sharding a table
      5. Summary
    12. 4. Performance Tuning and Advanced Queries
      1. Performance tuning
        1. Increasing the cache size
        2. Increasing concurrency
        3. Using soft durability mode
      2. Bulk data import
      3. Introducing indexing
      4. Evaluating query performance
      5. Creating and using an index
        1. Compound indexes
      6. Advanced queries
        1. Limits, skips, and sorts
          1. The limit command
          2. The skip command
          3. Sorting documents
        2. Finding a random document
        3. Grouping
        4. Aggregations
          1. Average
          2. Maximum
          3. The pluck command
      7. Summary
    13. 5. Programming RethinkDB in Node.js
      1. Introducing Node.js
        1. An increasingly popular technology
        2. An event-driven design
      2. Installing Node.js
        1. Installing on Linux
        2. Installing on Mac OS X
      3. Running Node.js
      4. Installing the RethinkDB module
      5. Connecting to RethinkDB
        1. Running a simple query
      6. Inserting documents
      7. Reading documents
      8. Updating and deleting documents
      9. Introducing Changefeeds
        1. A simple example using Changefeeds
      10. Summary
    14. 6. RethinkDB Administration and Deployment
      1. RethinkDB administration tools
        1. Backing up your data
        2. Backing up a single table
        3. Setting up automatic backups
      2. Restoring your data
      3. Securing RethinkDB
        1. Securing the web interface
        2. Securing the driver port
      4. Monitoring RethinkDB
        1. Monitoring issues
        2. Monitoring running jobs
      5. Deploying RethinkDB
      6. Summary
    15. 7. Developing Real-Time Web Applications
      1. Introducing real-time web applications
        1. Examples of real-time web apps
      2. Going real time on the Web
        1. Polling
        2. AJAX
        3. WebSockets
      3. Developing web applications with Node.js
        1. Express.js
        2. Routing
        3. Templating
        4. Socket.io
      4. Using RethinkDB in Node.js web applications
        1. Database polling
        2. Message queues
        3. Changefeeds
      5. Your first real-time web application
        1. Structuring the Notes web application
      6. Creating the Node.js server
      7. Configuring the router
      8. Writing the application logic
      9. Interacting with RethinkDB
        1. Implementing Changefeeds
      10. Programming Socket.io
      11. Programming the frontend
      12. The view
      13. Running our web application
      14. Summary
    16. Index