Book Image

Getting Started with RethinkDB

By : Gianluca Tiepolo
Book Image

Getting Started with RethinkDB

By: Gianluca Tiepolo

Overview of this book

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.
Table of Contents (15 chapters)
Getting Started with RethinkDB
Credits
About the Author
Acknowledgement
About the Reviewer
www.PacktPub.com
Preface
Index

Running a query


Now that we have a RethinkDB installation up and running, let's give it a quick try to make sure that everything is set up correctly. There are a few things that you might want to try to ensure that your database is running correctly. The first step is to try and access the web interface by browsing http://127.0.0.1:8080.

Tip

To access RethinkDB's web administration interface, you have to substitute 127.0.0.1 with the public IP that your instance is bound to.

If everything is working correctly, you'll see the RethinkDB web interface:

The web interface allows you to view the status of your cluster and manage each server independently. In the main view, we can see some standard health checks and cluster performance metrics, whereas at the bottom, we can find the most recently logged activities.

If we click on the Tables link at the top of the page, we can see all the tables that we have added to our database:

From this page, we can see all the databases that we have in the cluster. Within each database, we can see all the tables that we have created. As you can see from this screenshot, the cluster currently contains one database called test but no tables.

The web interface also provides a Data Explorer page that we can use to learn the query language and execute queries. If we click on the Data Explorer link, we are given an interface that allows us to interact with the server using the query language.

You now have an interactive shell at which you can issue commands. So, let's run our first query! Insert the following query into the Data Explorer:

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

This simple query creates a table called people inside the test database. If you execute the query by pressing the Run button, RethinkDB will create a new table and acknowledge the operation with a JSON document. As you can see, the Data Explorer is really easy to use and provides us with a great tool for high-level management of our databases and clusters.

Congratulations, you've just executed your first ReQL query! You'll get to learn the ReQL query language much better in the following chapter.

Tip

Downloading the example code

You can download the example code files for this book 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 files e-mailed directly to you.

You can download the code files by following these steps:

  • Log in or register to our website using your e-mail address and password

  • Hover the mouse pointer on the SUPPORT tab at the top

  • Click on Code Downloads & Errata

  • Enter the name of the book in the Search box

  • Select the book which you're looking to download the code files

  • Choose from the drop-down menu where you purchased this book from

  • Click on Code Download

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux