1

I am facing an issue where data in MongoDB inside EC2 instance is erased after approximately one day.

I use the AWS free tier service. In that I launch a t3.large ubuntu instance and gp3 8 GB volume. I connect with putty and install dependencies such as apache, node, npm, nvm, pm2, and for database mongodb using following commands

sudo apt-get install gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod
mongosh
sudo nano /etc/mongod.conf
# In that {bind 0.0.0.0}
sudo systemctl status mongod

After setup, data in MongoDB is erased automatically after one day.

What changes are required?

Greg Askew
  • 39,132

1 Answers1

0

Are you sure it's the same EC2 instance? With Elastic Beanstalk, for example, EC2 instances are ephemeral and you can't rely on persistence on the instance. Instead, you could try connecting to Atlas from the EC2 instance and the data should persist on Atlas.

Alex
  • 101