MongoDB Connection
The backend uses Mongoose to connect to MongoDB and manage data models.Database Setup
Connection is configured insrc/config/db.js:
src/config/db.js
Connection String
Add your MongoDB connection string to.env:
For local development, you can use
mongodb://localhost:27017/donpalitoDatabase Models
The backend uses 6 main Mongoose models:Product
Product catalog with images and ratings
User
User profiles with addresses and preferences
Cart
Shopping cart with product items
Order
Customer orders with payment info
Coupon
Discount coupons and promotions
Review
Product reviews and ratings
Product Model
Stores product information including name, price, images, and reviews.src/models/product.model.js
Product Fields
| Field | Type | Description |
|---|---|---|
name | String | Product name (required) |
description | String | Product description (required) |
price | Number | Price in Colombian pesos (required, min: 0) |
stock | Number | Available inventory (required, min: 0) |
category | String | Product category (required) |
images | Array | Array of Cloudinary image URLs |
averageRating | Number | Average rating 0-5 |
totalReviews | Number | Count of reviews |
User Model
Stores user profiles with Clerk integration, addresses, and wishlist.src/models/user.model.js
User Fields
Core Fields
Core Fields
clerkId- Clerk authentication ID (unique)email- User email address (unique)name- Full nameimageUrl- Profile picture URLstripeCustomerId- Stripe customer ID for payments
Addresses
Addresses
Array of address objects with:
label- Address name (e.g., “Home”, “Work”)fullName- Recipient namestreetAddress- Street addresscity- City namephoneNumber- Contact phoneisDefault- Default address flag
Preferences
Preferences
wishlist- Array of Product ObjectIdsisActive- Account statusemailNotifications- Receive order emailsmarketingEmails- Receive marketing emails
Personal Info
Personal Info
documentType- ID type (cedula_ciudadania, cedula_extranjeria, pasaporte)documentNumber- ID numbergender- masculino, femenino, otrodateOfBirth- Birth datephone- Phone number
Cart Model
Manages shopping cart items for each user.src/models/cart.model.js
Cart Structure
- Each user has one cart identified by
clerkId itemsarray contains cart items with:product- Reference to Productquantity- Number of items (min: 1)
Order Model
Stores completed orders with payment and shipping information.src/models/order.model.js
Order Status Flow
Order Fields
orderItems- Array of items with product reference, name, price, quantityshippingAddress- Delivery addresspaymentResult- Stripe payment detailstotalPrice- Total order amountstatus- Order status (see flow above)paidAt- Payment timestampdeliveredAt- Delivery timestamp
Coupon Model
Manages discount coupons with usage tracking.src/models/coupon.model.js
Coupon Types
Review Model
Stores product reviews with ratings.src/models/review.model.js
Review Validation
- Users can only review products from completed orders
- Rating must be between 1 and 5
- Comments are limited to 500 characters
- Reviews are linked to specific orders
Database Seeding
Populate the database with initial product data.Seed Products
src/seeds/index.js which:
- Connects to MongoDB
- Deletes existing products (uses transaction)
- Inserts 15 products across 5 categories:
- Palitos Premium (2 products)
- Palitos Cocteleros (4 products)
- Dulces (1 product)
- Especiales (6 products)
- Nuevos (3 products)
Seed Script
src/seeds/index.js:203-233