MongoDB Compass Setup Guide - cycotechnolgies/Online-Clothing-Shop GitHub Wiki
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.
MongoDB installed locally OR an active MongoDB Atlas cloud account
๐ Download from: https://www.mongodb.com/try/download/compass
- Download the installer from the official MongoDB Compass page.
- Run the installer and follow the installation wizard.
- Launch MongoDB Compass after installation.
๐ฅ๏ธ Local MongoDB Server
If you're using a locally installed MongoDB, use the default URI:
mongodb://localhost:27017
โ๏ธ MongoDB Atlas (Cloud)
-
Log into your MongoDB Atlas account.
-
Choose your cluster and click Connect > Connect using MongoDB Compass.
-
Copy the connection string. It will look like:
mongodb+srv://<username>:<password>@cluster0.mongodb.net/?retryWrites=true&w=majority
- Replace and with your actual credentials.
- Open MongoDB Compass.
- Paste the connection string into the "Connection String" field.
- Click Connect.
If the connection is successful, your databases will appear in the left sidebar.
- Click "Create Database".
- 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.
Collection | Description |
---|---|
products |
Stores clothing items |
users |
Registered customers and admins |
orders |
Stores order and payment info |
categories |
Clothing categories (blouse, skirt) |
-
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.
-
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
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));