NOSQL ecommerce db design

I am building an ecommerce app using MongoDB as the choice of database. So far, I have developed this schema for products and variations. However, I have some doubts about its scalability and implementation of the shopping cart functionality. Additionally, I am considering whether it would be better to separate the variations into another schema. I have made several modifications to the schema, and I am currently feeling confused. I would greatly appreciate any help or guidance in improving this schema.

It all started when I thought about the possibility of renaming a term, which led me to separate it into its own schema to ensure that the same _id is shared and any updates to the term are reflected across all instances. However, it seems there may be more to consider. Please assist me in refining this schema and addressing any potential issues. Thank you.

const productSchema = new mongoose.Schema({

    product_name: {
        type: String,
        required: true,
        index: true
    },
    slug: {
        type: String,
        required: true
    },
    product_description: {
        type: String,
        required: true
    },
    category_id: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'productscategories',
        required: true,
    },
    seller_id: {
        type: String,
    },
    product_type: {
        type: String,
        required: true
    },
    product_gallery: {
        type: Array,
        required: true
    },
    original_price: {
        type: Number,
    },
    sale_price: {
        type: Number,
        required: true
    },
    variations: [{
        attribute: {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'productsterms',
            required: true
        },
        terms: [
            {
                term: {
                    type: mongoose.Schema.Types.ObjectId,
                    ref: 'productsattributes',
                    required: true
                },
                sku: {
                    type: String,
                },
            }
        ]
    }],
    sku: {
        type: String,
    },
    quantity: {
        type: Number,
    },
}, { timestamps: true })

const productsAttributesSchema = new mongoose.Schema({
    attribute_name: {
        type: String,
        required: true,
        unique: true
    },
    slug: {
        type: String,
        unique: true,
    }
}, { timestamps: true } )

const productsTermsSchema = new Schema({
    term_name: {
        type: String,
        required: true,
        unique: true
    },
    slug: {
        type: String,
        unique: true
    },
    price: {
        type: Number,
        required: false,
    },
    attribute_id: {
        type: Schema.Types.ObjectId,
        required: true
    },
    image: {
        type: String,
        required: false,
    },
    is_default: {
        type: Boolean,
        default: false
    },
})

From my own experience, I can say that designing the schema can be challenging, especially when it involves scalability and incorporating shopping cart features.

It’s awesome that you’re building an e-commerce app with MongoDB as your database choice. Schema design can be tricky, especially when it comes to scalability and implementing shopping cart functionality. Considering separating variations into another schema sounds like a good idea for better organization. I understand the confusion you’re feeling with the modifications. Hopefully, the community here can provide you with helpful guidance to improve your schema. By the way, I recently stumbled upon a website where you can Hire Magento Developer if you need additional support. Just thought I’d share!

Another attempt at using generative AI to lure us.

See the similarities with Average date field in an aggregation - #6 by steevej, MongoDB consuming all available memory - #11 by Deepak_Kumar16 and Advice for modeling a database for multiple games - #7 by steevej

Lots of words, nice formatting and completely lack of specific details to an old thread. Just to include some SPAM. I like to keep them around so that others see rotten posts and eventually boycott the spammers. One day it will be so detrimental to SPAM that it will stop. Ah wishful (foolish) thinking.