Skip to content

Latest commit

Β 

History

History
149 lines (111 loc) Β· 3.72 KB

File metadata and controls

149 lines (111 loc) Β· 3.72 KB

MongoDB Setup Guide

You have two options for MongoDB:

Option 1: MongoDB Atlas (Recommended - Free Cloud Database)

Step-by-Step:

  1. Go to MongoDB Atlas

  2. Create a Free Cluster

    • Click "Build a Database"
    • Choose "M0 FREE" tier
    • Select a cloud provider and region (closest to you)
    • Click "Create Cluster"
  3. Create Database User

    • Go to "Database Access" in left menu
    • Click "Add New Database User"
    • Choose "Password" authentication
    • Username: stackora_admin
    • Password: Generate a secure password (save it!)
    • Database User Privileges: "Read and write to any database"
    • Click "Add User"
  4. Whitelist Your IP Address

    • Go to "Network Access" in left menu
    • Click "Add IP Address"
    • Click "Allow Access from Anywhere" (for development)
    • Or add your current IP address
    • Click "Confirm"
  5. Get Connection String

    • Go to "Database" in left menu
    • Click "Connect" on your cluster
    • Choose "Connect your application"
    • Copy the connection string (looks like):
    mongodb+srv://stackora_admin:<password>@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority
    
  6. Update .env File

    • Open .env file in your project
    • Replace <password> with your actual password
    • Replace the MONGODB_URI line:
    MONGODB_URI=mongodb+srv://stackora_admin:YOUR_PASSWORD@cluster0.xxxxx.mongodb.net/stackora?retryWrites=true&w=majority
    
    • Add /stackora before the ? to specify database name

Example .env with MongoDB Atlas:

MONGODB_URI=mongodb+srv://stackora_admin:MySecurePass123@cluster0.abc123.mongodb.net/stackora?retryWrites=true&w=majority

Option 2: Local MongoDB Installation

Windows:

  1. Download MongoDB

  2. Verify Installation

    mongod --version
  3. Start MongoDB Service

    • MongoDB should start automatically as a Windows service
    • Or manually: Open Services β†’ Find "MongoDB" β†’ Start
  4. Use Local Connection

    • Your .env already has the local connection:
    MONGODB_URI=mongodb://localhost:27017/stackora
    

βœ… After MongoDB is Set Up

Continue with these commands:

# Seed sample data (services, careers, projects)
node backend/scripts/seedData.js

# Create your admin account
node backend/scripts/createAdmin.js

# Start the application
npm run dev

πŸ” Verify Connection

When you run npm run dev, you should see:

βœ“ MongoDB connected
βœ“ Server running on port 5000

If you see connection errors, check:

  • MongoDB Atlas: IP whitelist, correct password, connection string format
  • Local MongoDB: Service is running, port 27017 is not blocked

πŸ“Š View Your Database

MongoDB Atlas:

  • Go to "Database" β†’ Click "Browse Collections"
  • You'll see your data after seeding

Local MongoDB:


πŸ†˜ Troubleshooting

"MongoNetworkError: failed to connect"

  • Check internet connection (Atlas)
  • Verify MongoDB service is running (Local)
  • Check firewall settings

"Authentication failed"

  • Verify username and password in connection string
  • Make sure you created a database user in Atlas

"IP not whitelisted"

  • Add your IP address in Atlas Network Access
  • Or use "Allow Access from Anywhere" for development

Need Help? Check the main SETUP_GUIDE.md for more details.