V
V
VKhotey2018-04-23 09:57:59
MySQL
VKhotey, 2018-04-23 09:57:59

What data to store in mongodb, in what data in mysql?

Hello! I am making a store, it has categories and I store their products in mysql with many to many relationships.
You can add an unlimited number of options and options to products, for example:
Option: Size; Options: m, l, s;
Option: Color; Options: blue, green;
I store options in mongodb so as not to create 3-4 more tables and then not to make large joins to collect options, options and products in mysql, in mongo the options look like this:

import mongoose, { Schema } from 'mongoose'

const ProductOptionSchema = new Schema({
  productId: {
    type: Number,
    required: true,
  },
  name: {
    type: String,
    required: true,
  },
  options: {
    type: [
      {
        name: {
          type: String,
          required: true,
        },
        value: {
          type: String,
          required: true,
        },
      },
    ],
    required: true,
  },
})

export default mongoose.model('productOption', ProductOptionSchema)

Questions:
1) To collect data, I first get the products from mysql, then I get the options by the id of the products and map them to the products, is this solution correct or is it better to transfer the data to mysql?
2) Also, in order not to create many tables, I thought to do a similar logic for orders, maybe in the mongo data structure the document can put all the information into it without creating many tables and relationships like in mysql?
3) What kind of data, information do you store in mongo ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sanovskiy, 2018-04-23
@Sanovskiy

Why do you need Mongo in this case? Options can be joined quite normally, provided that the indexes are set correctly. After the first time, the request will be cached and will work pretty quickly. This is provided that you write a query using binds.

O
OnYourLips, 2018-04-23
@OnYourLips

A good example of using mongo is logs from various sources. This is data without a strict structure.
But the data from the business logic fits perfectly into the SQL DBMS, because the entities are interconnected. Including your product properties divided into three tables (products themselves, property names, property values ​​for products). It is also possible to have a table for links between allowed properties and product categories. But this is a simplified model; in a more complex one, you will have to separate the name of the product from the article.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question