To migrate your local data to Atlas, first we have to export your local data. There are 2 ways to do this : using mongo CLI or using Compass. Let's keep it simple by using the GUI of Compass

  1. Click export collection. export_data1
  2. Choose Export Full Collection export_data2
  3. Choose all the data fields you want in your cloud server. export_data3
  4. Continue to export it under the json format. Make sure the json file name matches your collection name. It is a good practice to follow. export_data4

After signing in Mongo Atlas, you will be directed to the below site. From now we will start building a cloud server, and connect it to your local database.

  1. Click on Build a Database create_cluster1
  2. Choose the free option for practicing purposes. create_cluster2
  3. Select the closest server to Vietnam, in this case - is HongKong. create_cluster3
  4. You have created a cluster, let's continue to set up your database with username and passsword. For examples : username: admin & password: adminNote: These are important info, that will be used to connect to your cluster. ❗️ Please jot down and memorize it somewhere. create_cluster4
  5. Scroll down and add Entries - which IP address is authorized to write to your cluster? For now, let's follow the instruction and put 0.0.0.0 - which means your cluster can be accessed from everywhere. create_cluster5
  6. After Finish and Close you will be redirected to the Database. create_cluster6
  7. Your cluster is now ready to connect to the local Compass. Let's get URI. (URI is short for Uniform Resource Identifier ) create_cluster7create_cluster8
  8. Replace username and password with your real password and copy the URI. For example: mogo_uri/username:password/as1245.atlas.com..

create_cluster9

With the above steps, you already have a cloud server waiting. From now we will connect your local to the cloud via Mongo Compass.

  1. Paste your URI here to make new connection. mongo_compass1
  2. Look at the left corner to check up what server you're connecting to. If it's a cluster, you can now start importing data. mongo_compass2
  3. In tab Database, click on Create database. mongo_compass3
  4. Select your data type, in this case is json and Import. mongo_compass4
  5. This is the expected result. mongo_compass5

Now, let's get back to your Atlas!

  1. Switch to the Collections tab to see imported data checkup_atlast1

If you see your data then pad yourself in the back.

  1. In your .env, connect Atlas server to your backend project. heroku1heroku2
  2. Create Heroku account heroku3
  3. Create a new project with this button. heroku4heroku5
  4. Connect GitHub and Heroku heroku6heroku7heroku8
  5. Config Heroku env so that it point to your Atlas cluster for data query. Key: MONGO_URI. Value: your atlas Cluster URI. heroku9
  6. Choose the branch heroku10
  7. Now your app is ready to deploy. heroku11