K
K
Kasbolat Kumakhov2016-05-25 10:41:55
NoSQL
Kasbolat Kumakhov, 2016-05-25 10:41:55

What is the best way to organize the NOSQL database structure for a shopping application?

Kind.
To improve skills in NOSQL, I am writing an application for android to track product purchases.
Firebase is used as a backend.
An example structure is:

user_id
    category_list //список категорий продуктов, испоьзуется для разделения и визуальной раскраски
        category_name
            category_color
            product_list //список продуктов в этой категории
                product_name_1
                product_name_2
 
    product_list //общий список продуктов в базе, используется для автодополнения
        product_name_1
            product_description
            measure_unit 
            category_name //категория, к которой принадлежит этот продукт
        product_name_2
            product_description
            measure_unit  
            category_name
 
    cart_info_list //список созданных "корзин" с суммой покупок в ней
        cart_id
            cart_description
            cart_total

    cart_data_list //сами созданные "корзины" с непосредственно продуктами внутри
        cart_id
            product_seq_id
                product_name
                product_price

The essence is as follows:
1. the user opens the application, we read the contents of the "cart_info_list" branch and display the list of "carts"
2. the user selects the "cart", by its id we read the "cart_data_list/cart_id" branch directly and display the list of products of this "cart" "
2.1. at the same time, we read the entire branches "category_list" (for dividing products into categories) and "product_list" (for autocompleting names when adding a new product)
This is the minimum sequence of actions when working with this database.
Now regarding the question.
The user can freely transfer products from one category to another, change the category parameters (name, color, etc.), create new products in the directory or change the current ones.
When you change the category data, you need to change the links in the products. This is where the question lies: how best to organize it?
The Firebase docs talk about permanent data denormalization (I'm from the SQL world, so this is not very familiar to me). As examples, it is advised to duplicate data on different branches and update them simultaneously (by transactions, for example). They argue that by denormalizing the data, we reduce the number of calls to the database. For the same reason, I moved "cart_info_list" to a separate branch.
In this situation, the duplication is in the connection of categories with products. What is the correct way?
For example, now, when changing information in categories or products, you need to change the data in two branches.
One of the options I considered was to store the relationship in only one of the two places (either in categories or in products).
Another option was to remove these links from "category_list" and "product_list" and put them in a separate list like this:
product_category_map
    product_name : category_name

But for lack of sufficient experience in NOSQL, I don’t know which option is better to choose.
It is clear that this does not matter much in this project, but given that the application serves to gain experience, it would be better to process this moment from different angles, understanding the general principles for building such databases.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question