MongoDB Compass Setup Guide - cycotechnolgies/Online-Clothing-Shop GitHub Wiki

๐Ÿ“˜ MongoDB Compass Setup Guide

MongoDB Compass is the official GUI for MongoDB, allowing you to visualize, explore, and manage your data easily. This guide will help you set up Compass for local or cloud-based MongoDB instances.

โœ… Prerequisites

MongoDB installed locally OR an active MongoDB Atlas cloud account

MongoDB Compass installed

๐Ÿ‘‰ Download from: https://www.mongodb.com/try/download/compass

๐Ÿ Step-by-Step Guide

1. Install MongoDB Compass

  1. Download the installer from the official MongoDB Compass page.
  1. Run the installer and follow the installation wizard.
  1. Launch MongoDB Compass after installation.

2. Determine Your Connection Type

๐Ÿ–ฅ๏ธ Local MongoDB Server

If you're using a locally installed MongoDB, use the default URI:

mongodb://localhost:27017

โ˜๏ธ MongoDB Atlas (Cloud)

  1. Log into your MongoDB Atlas account.

  2. Choose your cluster and click Connect > Connect using MongoDB Compass.

  3. Copy the connection string. It will look like:

mongodb+srv://<username>:<password>@cluster0.mongodb.net/?retryWrites=true&w=majority
  1. Replace and with your actual credentials.

3. Connect via Compass

  1. Open MongoDB Compass.
  1. Paste the connection string into the "Connection String" field.
  1. Click Connect.

If the connection is successful, your databases will appear in the left sidebar.

4. Create a New Database and Collection

  1. Click "Create Database".
  1. Enter:
  • Database Name: clothing-shop
  • Collection Name: products or users, depending on your schema.
  • Click Create Database.

You can now visually insert documents or monitor your application data in real-time.


๐Ÿ“ Sample Collections You Might Use

Collection Description
products Stores clothing items
users Registered customers and admins
orders Stores order and payment info
categories Clothing categories (blouse, skirt)

๐Ÿ” Security Notes

  • Avoid hardcoding MongoDB credentials in your source code.

  • Use .env files and access them via process.env.

  • Set IP whitelisting rules in MongoDB Atlas to restrict access.

  • Enable user authentication for production databases.


โ“ Troubleshooting

  • Issue  Solution

  • Cannot connect to server  Ensure MongoDB is running locally or the Atlas IP is whitelisted

  • Authentication failed  Double-check username/password in URI

  • Compass freezes or crashes  Try reinstalling Compass or updating to the latest version

  • Data not appearing in Compass  Ensure your backend successfully writes data to the intended collection


๐Ÿงช Verify Connection in Your Project

In server/.env, set your connection URI like this:

MONGO_URI=mongodb://localhost:27017/olly-shop

Then in your backend code (e.g., index.js):

const mongoose = require('mongoose');

mongoose.connect(process.env.MONGO_URI)

  .then(() => console.log('MongoDB Connected'))

  .catch((err) => console.error('MongoDB Error:', err));
โš ๏ธ **GitHub.com Fallback** โš ๏ธ