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
restorerole on TeselaDB, orrootfor the migration. - The MongoDB Database Tools installed on a machine that can reach both.
1. Export from MongoDB
mongodump --uri "mongodb://user:<password>@mongo-01:27017/shop" --gzip --archive=shop.gzIf 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.
mongodump --uri "mongodb://user:<password>@mongo-01:27017/?replicaSet=rs0" --oplog --gzip --archive=all.gz2. Import into TeselaDB
mongorestore --uri "mongodb://root:<password>@node-01:27017/?tls=true&tlsCAFile=./ca.pem" \
--gzip --archive=shop.gzWith 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
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.pemCreate 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.
Last updated