Menu

SHOPSPHEREDB

 

SHOPSPHEREDB – MONGO DB E-COMMERCE 

 

INTRODUCTION

------------

ShopSphereDB is a MongoDB-based database designed for retail and e-commerce operations.

It manages employees, products, and customer orders in a structured and flexible way.

The database supports inventory management, employee tracking, and order processing.

 

----------------------------------------------------

DATABASE CREATION

----------------------------------------------------

 

use ShopSphereDB

 

MongoDB automatically creates the database when data is inserted.

 

----------------------------------------------------

COLLECTIONS OVERVIEW

----------------------------------------------------

 

1. employees → Stores staff information

2. products → Stores product inventory

3. orders → Stores customer orders

 

----------------------------------------------------

EMPLOYEES COLLECTION

----------------------------------------------------

 

Purpose:

Stores information about employees involved in business operations such as sales

and customer support.

 

Fields:

- _id : Unique employee ID

- name : Full name

- department : Department name

- email : Email address

- gender : Gender

- job_title : Job role

- salary : Monthly salary

 

Insert Sample Data:

 

db.employees.insertMany([

  {

    _id: 9001,

    name: "Angela Morris",

    department: "Customer Support",

    email: "amorris@shopsphere.com",

    gender: "Female",

    job_title: "Support Supervisor",

    salary: 4200

  },

  {

    _id: 9002,

    name: "Daniel Foster",

    department: "Sales",

    email: "dfoster@shopsphere.com",

    gender: "Male",

    job_title: "Sales Executive",

    salary: 5000

  }

])

 

----------------------------------------------------

PRODUCTS COLLECTION

----------------------------------------------------

 

Purpose:

Maintains the product catalog including pricing, categories, and discounts.

 

Fields:

- _id : Unique product ID

- category : Product category

- name : Product name

- brand : Brand name

- description : Product description

- quantity_per_unit : Quantity per unit

- unit_price : Price per unit

- image_url : Product image link

- discount : Discount percentage

 

Insert Sample Data:

 

db.products.insertMany([

  {

    _id: 101,

    category: "Electronics",

    name: "Wireless Mouse",

    brand: "LogiTech",

    description: "Ergonomic wireless mouse",

    quantity_per_unit: "1 Piece",

    unit_price: 25,

    image_url: "http://example.com/mouse.jpg",

    discount: 15

  },

  {

    _id: 102,

    category: "Home Appliances",

    name: "Electric Kettle",

    brand: "Philips",

    description: "1.5L electric kettle",

    quantity_per_unit: "1 Unit",

    unit_price: 40,

    image_url: "http://example.com/kettle.jpg",

    discount: 5

  }

])

 

----------------------------------------------------

ORDERS COLLECTION

----------------------------------------------------

 

Purpose:

Tracks customer purchases, delivery status, employees handling the orders,

and products purchased.

 

Fields:

- _id : Order ID

- orderDate : Date order was placed

- expectedDelivery : Expected delivery date

- deliveryStatus : Order status

- customer : Embedded customer information

- employee : Embedded employee handling the order

- items : Array of ordered products

 

Insert Sample Data:

 

db.orders.insertOne({

  _id: 50001,

  orderDate: ISODate("2024-11-10T00:00:00Z"),

  expectedDelivery: ISODate("2024-11-18T00:00:00Z"),

  deliveryStatus: "Delivered",

 

  customer: {

    customerId: "CUST1001",

    customerName: "Bright Stores Ltd",

    contactPerson: "Samuel Okoye",

    city: "Lagos"

  },

 

  employee: {

    name: "Daniel Foster",

    jobTitle: "Sales Executive"

  },

 

  items: [

    {

      productName: "Wireless Mouse",

      category: "Electronics",

      unitPrice: 25,

      quantity: 10,

      discountPercent: 15

    },

    {

      productName: "Electric Kettle",

      category: "Home Appliances",

      unitPrice: 40,

      quantity: 3,

      discountPercent: 5

    }

  ]

})

 

----------------------------------------------------

INDEXES (OPTIONAL BUT RECOMMENDED)

----------------------------------------------------

 

db.employees.createIndex({ department: 1 })

db.products.createIndex({ category: 1 })

db.products.createIndex({ discount: 1 })

db.orders.createIndex({ "employee.name": 1 })

db.orders.createIndex({ "customer.customerId": 1 })

 

----------------------------------------------------

COMMON QUERIES

----------------------------------------------------

 

Get all employees in Sales department:

db.employees.find({ department: "Sales" }).pretty()

 

Get products with discount greater than 10%:

db.products.find({ discount: { $gt: 10 } }).pretty()

 

Find orders handled by a specific employee:

db.orders.find({ "employee.name": "Daniel Foster" }).pretty()

 

Fetch orders for a specific customer:

db.orders.find({ "customer.customerId": "CUST1001" 

 

ShopSphereDB is a simple yet powerful MongoDB database for managing employees,

products, and orders in an e-commerce environment. It supports efficient querying,

scalability, and real-world business.