MongoDB Setup
MongoDB Setup Guide
PG requires a MongoDB database to store user data, settings, and logs.
You can choose between local MongoDB (on your computer/server) or MongoDB Atlas (cloud-hosted).
Option A: Local MongoDB
1. Install MongoDB
macOS (Homebrew)
brew tap mongodb/brew
brew install mongodb-community
## Ubuntu / Debian
sudo apt-get update
sudo apt-get install -y mongodb
Windows
-
Download the installer from MongoDB Community Download.
-
Run the installer and follow setup instructions.
-
Ensure mongod service is running.
- Start MongoDB Service
macOS / Linux
sudo service mongod start
Windows
net start MongoDB
Verify it’s running:
mongo --version
3. Create Database for PG
Connect to MongoDB:
mongosh
Then run:
use pg-bot
db.createCollection("users")
db.createCollection("settings")
Option B: MongoDB Atlas (Cloud)
- Go to MongoDB Atlas.
- Create a free account and a new Cluster.
- Under Database Access, add a new user with username & password.
- Under Network Access, allow connections from your IP or 0.0.0.0/0 (all IPs).
- Copy your connection string, it will look like this:
mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/pg-bot?retryWrites=true&w=majority
⚙️ Step 4: Update .env
Edit your .env file and set:
MONGO_URI=mongodb://localhost:27017/pg-bot
# Or Atlas example:
# MONGO_URI=mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/pg-bot
✅ Verify Connection
Run the bot:
npm run dev
If connected, you’ll see logs confirming MongoDB is running.