$ sudo apt install -y git
$ git --version
$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
$ sudo apt install -y nodejs
$ node -v
$ npm -v
$ sudo npm install -g pm2
$ pm2 -v
$ git clone https://github.com/nhungnguyen-9/e-commerce-furniture.git
Use the ls
command to check if the project has been cloned successfully
Navigate to the e-commerce-furniture directory and install dependencies
$ cd e-commerce-furniture
$ npm install
In this workshop, we will use the offline migration method. You can refer to other methods in this blog: Migrate from
MongoDB to Amazon
DocumentDB
Install mongosh
$ wget -qO - https://pgp.mongodb.com/server-6.0.asc | sudo tee /usr/share/keyrings/mongodb-server-key.asc
$ echo "deb [signed-by=/usr/share/keyrings/mongodb-server-key.asc] https://repo.mongodb.org/apt/ubuntu
focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
$ sudo apt update
$ sudo apt install -y mongodb-mongosh
$ mongosh --version
Check connection to DocumentDB
Go to the Amazon DocumentDB Cluster interface, then select the created cluster
Download the global-bundle.pem file to EC2 and connect to DocumentDB (replace insertYourPassword with your
actual password)
Run show dbs to check if there are any databases in DocumentDB
Next, proceed with data migration
Install MongoDB Database Tools
$ wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.9.0.tgz
$ tar -xvzf mongodb-database-tools-ubuntu2204-x86_64-100.9.0.tgz
$ sudo mv mongodb-database-tools-ubuntu2204-x86_64-100.9.0/bin/* /usr/local/bin/
$ sudo apt install -y mongodb-mongosh
$ mongodump --version
$ mongodump
--uri="mongodb+srv://nguyennhung9846:3siHCKWL69z5DoS1@nhaxinh.02uuoha.mongodb.net/?retryWrites=true&w=majority&appName=nhaxinh"
--out=backup
$ ls
$ mongorestore --uri="mongodb://user123:<insertYourPassword>
@docdb-nextjs-workshop.cluster-c10k88ou8amc.ap-southeast-1.docdb.amazonaws.com:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false"
--dir=backup --drop
$ ls
$ show dbs
$ use test
$ show collections
$ touch .env
$ nano .env
Download the .env file and add the required variables .env
npm run build
pm2 start npm --name "nextjs-app" -- run start
pm2 save
pm2 startup
pm2 list
http://your-ec2-public-ip:3000
mongosh docdb-nextjs-workshop.cluster-c10k88ou8amc.ap-southeast-1.docdb.amazonaws.com:27017 --tls --tlsCAFile
global-bundle.pem --retryWrites=false --username user123 --password <your-cluster-documentdb-password>
```
- Check the stored data
```
use test
show collections
db.your-collection.find().pretty()
```

### **Completed! 🚀**