Marketplace
Databases

MongoDB

MongoDB 7 Community Edition with auth enabled.

Deploy this app

About

Installs MongoDB Community Edition from the official repository, enables authentication, and creates an admin user with a generated password.

Restrict the firewall's source CIDR to your own private subnet. Admin credentials are in /root/mongodb-credentials.txt.

Ports opened by the installer

27017/tcp · MongoDB

Install script (runs as cloud-init user-data on first boot)

#!/bin/bash
set -e
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
apt-get install -y gnupg curl
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg
. /etc/os-release
echo "deb [signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] https://repo.mongodb.org/apt/ubuntu $UBUNTU_CODENAME/mongodb-org/7.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-7.0.list
apt-get update -y
apt-get install -y mongodb-org
systemctl enable --now mongod
DB_PASS=$(openssl rand -base64 18 | tr -dc 'A-Za-z0-9')
sleep 5
mongosh --eval "db.getSiblingDB('admin').createUser({user:'admin',pwd:'$DB_PASS',roles:[{role:'root',db:'admin'}]})"
sed -i "s/^  bindIp:.*/  bindIp: 0.0.0.0/" /etc/mongod.conf
sed -i "/^security:/,+0 s//security:\n  authorization: enabled/" /etc/mongod.conf || echo -e "security:\n  authorization: enabled" >> /etc/mongod.conf
systemctl restart mongod
echo "admin / $DB_PASS" > /root/mongodb-credentials.txt