Reputation: 634
When you launch a rethinkdb instance, it will automatically create a database called 'test'. When you run multiple instances and cluster them using rethinkdb proxy
this leads to the issue:
Database name conflict: test is the name of more than one database
If you try to delete the databases i.e using
r.dbDrop('test').run(conn, function(result) {
console.log(result) // Will result in error
});
This will produce the following error:
ReqlOpFailedError: Database 'test' is ambiguous; there are multiple databases with that name in r.dbDrop("test")
So how to prevent RethinkDB from creating the 'test' database automatically? Or how to remove a database if you run into name conflict?
Upvotes: 3
Views: 667
Reputation: 7184
If you use rethinkdb create
to create a data directory, no test
database will be created.
For example, if rethinkdb_data
doesn't exist, this will create it with no test
database:
rethinkdb create
rethinkdb
This will do the same, but uses -d
to specify the location of the data directory:
rethinkdb create -d /var/lib/rethinkdb/data
rethinkdb -d /var/lib/rethinkdb/data
Upvotes: 1
Reputation: 634
After digging for a while I didn't find any good options to prevent RethinkDB from trying to create the default test
database on startup. The problem above only occurs when the cluster nodes use different data directories. Otherwise they will not try to create extra test
databases as the other nodes will simply recognise it already exists (created by the first node that launched).
I ended up solving this in my backend software by enumerating all database named test
during startup from the db_config
table in rethinkdb
database.
Example:
// Read from the database 'rethinkdb' that holds information about other databases
r.db("rethinkdb")
// Table db_config contains database id, name information
.table("db_config")
// Filter by name 'test'
.filter({name: "test"})
.run(conn, function(err, cursor) {
// Get results from cursor by id and rename
cursor.each(function(err, result){
r.db("rethinkdb")
.get(result.id)
.update({name: "other_name"})
.run(conn, function(err, result) {
console.log(result.replaced);
});
});
});
Upvotes: 0