Migrate from MongoDB with mongodump and mongorestore

Move a MongoDB database to TeselaDB with the tools you already use and change the connection string.

TeselaDB speaks the MongoDB protocol, so the migration uses mongodump and mongorestore, the MongoDB database tools. Your application does not change: only its connection string.

Before you start

  • A running TeselaDB cluster (Your first cluster) and its CA, pki/ca.pem.
  • A user with the restore role on TeselaDB, or root for the migration.
  • The MongoDB Database Tools installed on a machine that can reach both.

1. Export from MongoDB

Shell
mongodump --uri "mongodb://user:<password>@mongo-01:27017/shop" --gzip --archive=shop.gz

If you do not want to stop writes during the copy, export the whole replica set with --oplog: the archive includes the operations that happen while the export runs.

Shell
mongodump --uri "mongodb://user:<password>@mongo-01:27017/?replicaSet=rs0" --oplog --gzip --archive=all.gz

2. Import into TeselaDB

Shell
mongorestore --uri "mongodb://root:<password>@node-01:27017/?tls=true&tlsCAFile=./ca.pem" \
  --gzip --archive=shop.gz

With an archive made with --oplog, add --oplogReplay to apply those operations at the end. mongorestore also creates the indexes, and TeselaDB splits each collection into ranges as the documents arrive.

3. Check the data

JavaScript
db.orders.countDocuments();
db.orders.getIndexes();

Compare the counts and indexes with MongoDB's before moving the traffic.

4. Change the connection string

mongodb://shop-api:<password>@node-01:27017,node-02:27017,node-03:27017/shop?tls=true&tlsCAFile=./ca.pem

Create a user for the application with only the roles it needs (Users and roles) and check Differences with MongoDB in case your application depends on a behaviour that changes, such as the order of a find without sort.