Skip to main content

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

  1. Download the installer from MongoDB Community Download.

  2. Run the installer and follow setup instructions.

  3. Ensure mongod service is running.


  1. 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)

  1. Go to MongoDB Atlas.
  2. Create a free account and a new Cluster.
  3. Under Database Access, add a new user with username & password.
  4. Under Network Access, allow connections from your IP or 0.0.0.0/0 (all IPs).
  5. 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.