RethinkDB JavaScript Driver

2.4.2 · maintenance · verified Wed Apr 22

The RethinkDB JavaScript driver provides programmatic access to RethinkDB, a NoSQL database known for its real-time capabilities via push queries. It is primarily designed for Node.js environments and implements the ReQL query language. The current stable version is 2.4.4. After a period of inactivity from the original creators, the project transitioned to community-driven maintenance under the Linux Foundation, with recent 2.4.x releases (2023-2024) addressing bug fixes and compilation issues. Its key differentiator remains the 'changefeeds' feature, which allows applications to receive real-time updates as data changes. While the official documentation is still available, the release cadence is irregular, reflecting its community-supported status.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates connecting to RethinkDB, creating a table if it doesn't exist, inserting a document, and fetching all documents.

const r = require('rethinkdb');

async function runExample() {
  let connection;
  try {
    connection = await r.connect({
      host: process.env.DB_HOST ?? 'localhost',
      port: parseInt(process.env.DB_PORT ?? '28015'),
      db: process.env.DB_NAME ?? 'test',
      user: process.env.DB_USER ?? 'admin',
      password: process.env.DB_PASSWORD ?? ''
    });

    // Create a table if it doesn't exist
    const tableList = await r.db('test').tableList().run(connection);
    if (!tableList.includes('authors')) {
      await r.db('test').tableCreate('authors').run(connection);
      console.log('Table "authors" created.');
    }

    // Insert a document
    const insertResult = await r.table('authors').insert({
      name: 'John Doe',
      posts: 5
    }).run(connection);
    console.log('Inserted:', insertResult.generated_keys[0]);

    // Fetch all documents
    const cursor = await r.table('authors').run(connection);
    const authors = await cursor.toArray();
    console.log('Authors:', authors);

  } catch (err) {
    console.error('Error:', err.message);
  } finally {
    if (connection) {
      await connection.close();
      console.log('Connection closed.');
    }
  }
}

runExample();

view raw JSON →