GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Close
  • FAQ
  • Docs
  • API
  • Community
  • Blog
  • Accessing ReQL
  • r
  • close
  • reconnect
  • use
  • run
  • changes
  • noreplyWait

This view

  • Original page
  • New address

GeezerVison is showing rethinkdb.com — ReQL command reference - RethinkDB


▲ Back to top

Command syntax

r.connect([options, ]callback)

r.connect([host, ]callback)

r.connect([options]) → promise

r.connect([host]) → promise

Description

Create a new connection to the database server. Accepts the following options:

  • host: the host to connect to (default localhost).
  • port: the port to connect on (default 28015).
  • db: the default database (default test).
  • user: the user account to connect as (default admin).
  • password: the password for the user account to connect as (default '', empty).
  • timeout: timeout period in seconds for the connection to be opened (default 20).
  • ssl: a hash of options to support SSL connections (default null). Currently, there is only one option available, and if the ssl option is specified, this key is required:
    • ca: a list of Node.js Buffer objects containing SSL CA certificates.

If the connection cannot be established, a ReqlDriverError will be passed to the callback instead of a connection.

The returned connection object will have two properties on it containing the connection’s port and address:

conn.clientPort;
conn.clientAddress;

Using SSL with RethinkDB requires proxy software on the server, such as Nginx, HAProxy or an SSL tunnel. RethinkDB will encrypt traffic and verify the CA certification to prevent man-in-the-middle attacks. Consult your proxy’s documentation for more details.

Alternatively, you may use RethinkDB’s built-in TLS support.

Example: Open a connection using the default host and port, specifying the default database.

r.connect({
    db: 'marvel'
}, function(err, conn) {
    // ...
});

If no callback is provided, a promise will be returned.

var promise = r.connect({db: 'marvel'});

Example: Open a new connection to the database.

r.connect({
    host: 'localhost',
    port: 28015,
    db: 'marvel'
}, function(err, conn) {
    // ...
});

Alternatively, you can use promises.

var p = r.connect({
    host: 'localhost',
    port: 28015,
    db: 'marvel'
});
p.then(function(conn) {
    // ...
}).error(function(error) {
    // ...
});

Example: Open a new connection to the database, specifying a user/password combination for authentication.

r.connect({
    host: 'localhost',
    port: 28015,
    db: 'marvel',
    user: 'herofinder',
    password: 'metropolis'
}, function(err, conn) {
    // ...
});

Example: Open a new connection to the database using an SSL proxy.

var fs = require('fs');
fs.readFile('/path/to/cert', function (err, caCert) {
    if (!err) {
        r.connect({
            host: 'localhost',
            port: 28015,
            db: 'marvel',
            authKey: 'hunter2',
            ssl: {
                ca: caCert
            }
        }, function(err, conn) {
            // ...
        });
    } else {
        console.log(err);
    }
});

Related commands

  • use
  • close

Get more help

Couldn't find what you were looking for?

  • Ask a question on Stack Overflow
  • Chat with us and our community on Slack
  • Talk to the team on IRC on #[email protected] — via Webchat
  • Ping @rethinkdb on Twitter
  • Post an issue on the documentation issue tracker on GitHub

Contribute: edit this page or open an issue

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.