We get a lot of questions about how to migrate databases from Compose to IBM Cloud Databases, and we've been working hard to put together guides that show you how you can make these migrations.
A lot of guidance that we have been distributing are for situations where there is a like-for-like databases on Compose to IBM Cloud Databases. However, for databases like RethinkDB that exist only on Compose, the question remains—what options do you have?
On IBM Cloud, you have two options if you want to keep your data in a traditional NoSQL database: IBM Cloudant and IBM Cloud Databases for MongoDB. If you're considering IBM Cloudant, we recommend reviewing the options are available for that database and taking a look at the couchimport npm package. Otherwise, to migrate to IBM Cloud Databases for MongoDB, we suggest using MongoDB's native
In this article, we're focusing on IBM Cloud Databases for MongoDB. We'll guide you through the process of downloading your data from RethinkDB and importing that data into IBM Cloud Databases for MongoDB using
Let's get started . . .
Extracting your Compose for RethinkDB data
For this example, you'll need the
rethinkdb command line tool installed on your system in order to communicate with RethinkDB and extract the data from your database. Using macOS and homebrew, you can install it using
brew install rethinkdb. For other systems, consult the RethinkDB documentation.
In this scenario, I have one database called
example and two tables that comprise data of
states. The image below shows these tables from the RethinkDB administrator UI. To translate to MongoDB, think of tables in RethinkDB as MongoDB collections. RethinkDB has databases and tables, while MongoDB has databases and collections.
From here, you can download the data JSON documents using the
rethinkdb-dump command link tool. This comes with
rethinkdb when you install it on your system. Using
rethinkdb-dump, provide your RethinkDB credentials and run the following from the command line:
-c flag, provide the host and port of your RethinkDB deployment. For the password, I've used
--password-file and put the password in a text file for the command to read. You will need the
--tls-cert flag and the path to your self-signed certificate as well.
Once you run that command, it will download a gzip file to the directory that you're currently in on your system. It will look something like
rethinkdb_dump_<date_time>.tar.gz. You'll need to unzip that file using, for instance:
Within the unzipped file, your databases will be separated into folders. Each database will contain your tables as
.info files. The
.json files will contain actual data as a JSON array that you'll import into MongoDB. The
.info files will contain the indices of your tables. You will not be able to restore the indices you set up in RethinkDB to MongoDB. However, after importing your data into MongoDB, you can use MongoDB's excellent indexing to recreate the indices you had previously.
Importing Data into MongoDB
Now that your data has been downloaded and unzipped, you can start the process of importing it into IBM Cloud Databases for MongoDB. Make sure that you have MongoDB installed on your system. Again, if you're using macOS and homebrew, you can install it using
brew install mongodb. If you're using another system, check out MongoDB's documentation on how to get set up.
I assume that you've already provisioned IBM Cloud Databases for MongoDB database. If not, we have some provisioning guidance in our documentation. With MongoDB installed on your system and your new MongoDB database on IBM Cloud, you can use the
mongoimport tool to import your downloaded RethinkDB data:
Using the credentials provided from the IBM Cloud UI for your Databases for MongoDB deployment, you'll be able to add the required information to
mongoimport. Using the
admin user, for instance, supply the deployment's
admin password next to
--host, use the deployment's replica set URI string that starts with
replset.... You can find this information in the Connections panel of your MongoDB deployment on the IBM Cloud UI.
If you're using the
admin credential, designate that the
admin database is the
--authenticationDatabase. Since you're connecting using a TLS connection, use the
--tls flag and indicate the location of your database's self-signed certificate using the
--tlsCAFile flag. Since your RethinkDB data was downloaded and placed into individual JSON files as a JSON array, you'll need to add the
--jsonArray flag as well. Finally, because each of the files that were downloaded are separate RethinkDB tables, you'll need to individually import each one into MongoDB by using the
-c flag to indicate the collection name and the corresponding
.json file you want to import.
After you've run the import command, make sure that your data has been imported into MongoDB. Then, recreate the indices using MongoDB's indexing strategies to efficiently execute queries.
We focused on Compose for RethinkDB in this article, but if you’re looking to migrate other databases from Compose to IBM Cloud Databases, we’ve got you covered in the following articles and documentation:
- Compose for Elasticsearch
- Compose for Redis
- Compose for PostgreSQL
- Compose for RabbitMQ
- Compose for MongoDB
If you still have questions, reach out—our support team is always ready to lend a hand.