This hands-on lab guides you through the process of migrating a legacy application from a relational database to MongoDB. The existing application has an API based on a relational database management system (RDBMS). Our goal is to create a version 2 (v2) of this API that can read the same data using MongoDB instead.
By completing this lab, you'll learn how to:
- Set up a MongoDB Atlas cluster
- Use a Docker container for the migration process
- Migrate data from an RDBMS to MongoDB
- Build MongoDB queries for the new API v2
Before starting this lab, ensure you have the following:
- Docker Desktop or Docker Rancher installed on your machine
- You should be able to pull and run Docker containers
- A MongoDB Atlas account
- If you don't have one, you can create a free account at https://www.mongodb.com/cloud/atlas
-
Log in to your MongoDB Atlas account and create a new free cluster.
-
Whitelist your IP address:
- In the Atlas dashboard, go to Network Access
- Add a new IP address
- Enter
0.0.0.0to allow access from anywhere (Note: This is not recommended for production environments)
-
Create a database user:
- In the Atlas dashboard, go to Database Access
- Add a new database user with read and write privileges
Open a terminal and run the following commands:
docker pull [your-image-name]
docker run -it [your-image-name]Replace [your-image-name] with the actual name of your Docker image.
-
Connect to the RDBMS:
- Use the provided credentials to connect to your legacy relational database
-
Connect to MongoDB Atlas:
- Use the connection string from your Atlas cluster to connect to MongoDB
-
Map tables to documents:
- Start with an Empty Schema
- Design your MongoDB Documents
- Run the migration process
With your data now in MongoDB, you can start building queries for your new API v2:
- Identify the key operations from your v1 API
- Translate SQL queries to MongoDB queries
- Test and optimize your new MongoDB-based API endpoints
Congratulations! You've successfully migrated your data from a relational database to MongoDB and prepared for the new version of your API.