connect
ReQL command: connect
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 (defaultlocalhost
). -
port
: the port to connect on (default28015
). -
db
: the default database (defaulttest
). -
user
: the user account to connect as (defaultadmin
). -
password
: the password for the user account to connect as (default''
, empty). -
timeout
: timeout period in seconds for the connection to be opened (default20
). -
ssl
: a hash of options to support SSL connections (defaultnull
). Currently, there is only one option available, and if thessl
option is specified, this key is required:-
ca
: a list of Node.jsBuffer
objects containing SSL CA certificates.
-
If the connection cannot be established, a ReqlDriverError
will be passed to the callback instead of a connection.
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
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 #rethinkdb@freenode.net — via Webchat
- Ping @rethinkdb on Twitter
- Post an issue on the documentation issue tracker on GitHub
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/javascript/connect/