Mongo Schema Design
Mongo Schema Design
List of Entity
1. User
• User ID
• Username
• Email
• Password (hashed for security)
• First Name
• Last Name
• Address (with fields for street, city, state, country, postal
code)
• Phone Number
• Profile Picture (optional)
2. Product
• Product ID
• Name
• Description
• Price
• Stock Quantity
• Category ID
• Images (array of image URLs or IDs)
• Ratings (average rating, number of ratings)
• Seller ID
3. Category
• Category ID
• Name
• Description
• Parent Category ID (for nested categories)
4. Order
• Order ID
• User ID (who placed the order)
• Order Date
• Total Amount
• Shipping Address
• Billing Address
• Order Status (e.g., pending, completed, shipped,
cancelled)
• Payment Method
• List of Products (Product ID, quantity, price)
5. Cart
• Cart ID
• User ID
• List of Products (Product ID, quantity)
• Total Price
6. Payment Details
• Payment ID
• User ID
• Card Details (number, expiry date, CVV - encrypted for
security)
• Billing Address
7. Shipping Details
• Shipping ID
• Order ID
• Carrier Information
• Tracking Number
• Estimated Delivery Date
• Status (e.g., in transit, delivered)
8. Review
• Review ID
• Product ID
• User ID
• Rating
• Comment
• Date of Review
9. Seller
• Seller ID
• Name
• Email
• Contact Information
• Address
• List of Products Sold
10. Discounts/Promotions
• Discount ID
• Description
• Discount Percentage or Amount
• Start Date
• End Date
• Applicable Products or Categories
MongoDB Schema
Users Collection
{
"_id": ObjectId,
"username": String,
"email": String,
"passwordHash": String,
"firstName": String,
"lastName": String,
"address": {
"street": String,
"city": String,
"state": String,
"country": String,
"postalCode": String
},
"phoneNumber": String,
"profilePicture": String
}
Products Collection
{
"_id": ObjectId,
"name": String,
"description": String,
"price": Decimal128,
"stockQuantity": Number,
"category": ObjectId,
"images": [String],
"ratings": {
"average": Decimal128,
"numberOfRatings": Number
},
"seller": ObjectId
}
Categories Collection
{
"_id": ObjectId,
"name": String,
"description": String,
"parentCategory": ObjectId
}
Orders Collection
{
"_id": ObjectId,
"user": ObjectId,
"orderDate": Date,
"totalAmount": Decimal128,
"shippingAddress": { ... },
"billingAddress": { ... },
"status": String,
"paymentMethod": String,
"products": [
{
"product": ObjectId,
"quantity": Number,
"price": Decimal128
}
]
}
Carts Collection
{
"_id": ObjectId,
"user": ObjectId,
"products": [
{
"product": ObjectId,
"quantity": Number
}
],
"totalPrice": Decimal128
}
PaymentDetails Collection
{
"_id": ObjectId,
"user": ObjectId,
"cardDetails": {
"number": String,
"expiryDate": Date,
"cvv": String
},
"billingAddress": { ... }
}
ShippingDetails Collection
{
"_id": ObjectId,
"order": ObjectId,
"carrier": String,
"trackingNumber": String,
"estimatedDeliveryDate": Date,
"status": String
}
Reviews Collection
{
"_id": ObjectId,
"product": ObjectId,
"user": ObjectId,
"rating": Number,
"comment": String,
"date": Date
}
Sellers Collection
{
"_id": ObjectId,
"name": String,
"email": String,
"contactInfo": String,
"address": { ... },
"productsSold": [ObjectId]
}
Discounts Collection
{
"_id": ObjectId,
"description": String,
"discountPercentage": Decimal128,
"startDate": Date,
"endDate": Date,
"applicableProducts": [ObjectId],
"applicableCategories": [ObjectId]
}
Use Cases Structure for E-commerce Application
Success Scenario:
Extensions:
• The product addition fails if mandatory fields like name,
price, or category are missing.
• The process is aborted if the seller is not logged in or lacks
the necessary permissions.