I'm having doubts with my products structure with MongoDB

Viewed 17

I'm developing an ECommerce React App with MERN ( MongoDB, Express, React and Node ), I was trying to develop a structure to prodcuts specifications. ( Like Size, Color, etc ) I made it, but its causing bugs and seems a bad way to implement what I want to. If someone can say to me a proper way to do that I'm going to be very thankful. I'm going to explain how it works right now and the problems I'm having with it:

This is a product structure, you have all his informations.


{
  "_id": {
    "$oid": "630ff91fdc892b42e410355c"
  },
  "name": "Perfume 4",
  "images": [
    "image url"
  ],
  "shortDescription": "lançame3nto",
  "description": "lançament3o lançamento lançamento lançamento lançamento lançamento lançamento lançamento lançamento lançamento lançamento lançamento lançamento lançamentolançamento",
  "stock": {
    "$numberInt": "20"
  },
  "price": {
    "$numberInt": "110"
  },
  "inStock": true,
  "variations": [
    {
      "tamanho": "P",
      "cor": "Amarelo",
      "quantity": {
        "$numberInt": "3"
      }
    },
    {
      "tamanho": "G",
      "cor": "Branco",
      "quantity": {
        "$numberInt": "4"
      }
    },
    {
      "tamanho": "P",
      "cor": "Preto",
      "quantity": {
        "$numberInt": "2"
      }
    },
    {
      "tamanho": "G",
      "cor": "Amarelo",
      "quantity": {
        "$numberInt": "1"
      }
    }
  ],
  "categories": [
    "category"
  ],
  "createdAt": {
    "$date": {
      "$numberLong": "1661991199286"
    }
  },
  "updatedAt": {
    "$date": {
      "$numberLong": "1661991199286"
    }
  },
  "__v": {
    "$numberInt": "0"
  }
}

We can see that we have an "variations" array, which contains all the varieties of this product. Which "tamanho" is size and "cor" is color. The thing with this is that I don't know if im doing this properly, it just looks like a mess and I think theres a better way to do this data structure, can someone help me?

I want something easy to check the stock of each variation, this is causing some bugs to me.

0 Answers
Related