Migrate from MongoDB Atlas

TeselaDB

TeselaDB

TeselaDB team

40 minIntermediate

Copy an Atlas database to your TeselaDB cluster with its search indexes and change the connection string.

Migrating from Atlas uses the same tools as from MongoDB: mongodump with the Atlas mongodb+srv string and mongorestore against TeselaDB. What mongodump does not copy is the search indexes, so you note them first and create them again at the end.

What you will build

The Atlas shop database copied into your TeselaDB cluster with its regular indexes and its search indexes, and at the end your application pointing to the new cluster.

Requirements

  • An Atlas user with read permission on the database and your machine's IP in the Atlas access list.
  • A TeselaDB cluster, its CA (pki/ca.pem) and a user with the restore role.
  • The MongoDB Database Tools and mongosh on a machine that reaches both Atlas and TeselaDB.

1. Note the search indexes

Open mongosh against Atlas and save the definition of each search index of each collection:

JavaScript
db.products.getSearchIndexes();

2. Export from Atlas

Shell
mongodump --uri "mongodb+srv://user:<password>@cluster0.example.mongodb.net/shop" --gzip --archive=shop.gz

3. Import into TeselaDB

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

mongorestore creates the regular indexes. Atlas features that are not MongoDB ones, such as Atlas triggers, do not travel in the archive.

4. Create the search indexes again

In mongosh on TeselaDB, create each search index again with the definition you noted in step 1, as the example below does for the default index of products with dynamic mappings:

JavaScript
db.products.createSearchIndex("default", { mappings: { dynamic: true } });

Try it

In TeselaDB, the counts and the indexes of each collection match those in Atlas, and a search returns results as soon as its index has been built. Compare the count below with the one that countDocuments() gives in Atlas:

JavaScript
db.products.countDocuments();
db.products.aggregate([{ $search: { text: { query: "chair", path: { wildcard: "*" } } } }, { $limit: 3 }]);

When everything matches, change your application's connection string to the TeselaDB cluster's one.

Clean up

Delete the export archive once the data is in TeselaDB, because it holds all your data unencrypted:

Shell
rm shop.gz

Next steps