Google Cloud Nightscout » Import data from Atlas
Even though Heroku is not free any longer, you can still transfer your database for free as it is on Atlas and not Heroku. This page explains how to do it.
In order to transfer a database from Atlas, you need to have already completed Nightscout installation.
First, you need to use mongodump to get a backup of your database. Let’s assume you want to do that using Windows. Download the Database tools MSI installer zip file from this page.
Let’s say you download to your desktop. Extract all.
Now, you will have the mongodump.exe file inside the uncompressed folder at: Desktop/mongodb-database-tools-windows-x86_64-100.7.0/mongodb-database-tools-windows-x86_64-100.7.0/bin/mongodump.exe. We will use this later.
You will need the email address and password associated with your Atlas account. We all had to sign up in 2020.
Go to mongodb and sign in. In the left pane, click on Database Access.
You will be taken to the Database Access page. Take note of the user name (enclosed in orange in the following image). You will need it later.
On the right, click on “Edit”.
You will be taken to the page shown below.
If you don’t remember the password (this is not the password you use to log into Atlas) or if your password contains special characters, click on Edit Password and change the password. Take note of the password because you will need it later.
In the left pane, click on “Database” to go back to the main page. Click on the 3-dot menu button and click on “Command Line Tools” as shown in the following image.
Under “Binary Import and Export Tools”, copy the mongodump string. You can do that by clicking on the copy symbol on the right side of the string, as marked in the image below.
Open a “Windows Terminal” after right clicking on Start.
Type and enter cd Desktop. Type cd and press TAB to fill the folder name. Press ENTER. Again, Type cd and press TAB and ENTER.
Now, type and enter cd bin.
Type and enter ls. You should see the commands, including mongodump.exe that we will use, as shown below.
Paste the mongodump string you copied, from the binary import and export tools, into the terminal. It will be similar to what is shown in the followiong figure.
There are three changes you need to make to this string before executing it.
1- Replace mongodump with ./mongodump.exe
2- Replace <PASSWORD>, including the brackets, with your Atlas database admin password, which excludes special characters.
3- Replace <DATABASE>, including brackets, with the user name you copied from the Atlas database access page.
What you will have in the terminal after these three changes should look like the following.
Wait for the export process to complete. It could take a few minutes. If it succeeds, you will see something as shown below.
We now need to transfer the output of mongodump to the virtual machine. The output is a folder located where we ran the mongodump command. Use windows explorer and navigate to Desktop\mongodb-database-tools-windows-x86_64-100.7.0\mongodb-database-tools-windows-x86_64-100.7.0\bin. You should see what is shown in the following figure.
Right click the dump folder and select “Compress to ZIP file”. Now, we have a ZIP file. Please upload it to your virtual machine.
We first need to unzip the file we uploaded to the virtual machine.
Go to your home directory, where the dump.zip file should be after the upload. Type and enter the following.
If you see the following message, it means that the unzip command is not installed.
If unzip is not installed, type and enter the following two commands in sequence to install it.
sudo apt-get update sudo apt-get install unzip
If unzip was not installed and you installed it, run the unzip command again. The dump folder should be in your home directory.
Now, enter the following in the terminal replacing UserName with the user name you copied from the Atlas database access page.
mongorestore -d Nightscout ./dump/UserName
If it succeeds, you will see something as shown below.
Wait a minute. Reload Nightscout in a browser. Your imported data from Atlas should be present now.