Должен ли я разделять вложенные документы в отдельные коллекции или нет, в MongoDB? - PullRequest
0 голосов
/ 27 февраля 2019

У меня есть следующий набор данных в MongoDB:

{
    "_id" : ObjectId("5c73cc96c2fb92219aeb476a"),
    "menus" : {
        "name" : "Menu",
        "sections" : [ 
            {
                "name" : "Small Plates",
                "items" : [ 
                    {
                        "name" : "Savory Pancakes",
                        "description" : "Choice of vegetarian of seafood options.",
                        "price" : null
                    }, 
                    {
                        "name" : "Kimbop",
                        "description" : "Wrapped in seaweed paper with assorted vegetables. BBQ Beef, Spicy Pork, Chicken, Spicy Fish Cake, Spam (Gluten Free), Spicy Kimchi (Gluten Free), Vegetable (Gluten Free).",
                        "price" : "8.0"
                    }, 
                    {
                        "name" : "Bacon Roll",
                        "description" : "4 pieces. Seasoned rice rolled in bacon strip.",
                        "price" : "8.0"
                    }, 
                    {
                        "name" : "Fried Potstickers",
                        "description" : "8 pieces.",
                        "price" : "8.0"
                    }
                ]
            }, 
            {
                "name" : "Noodles & Soup",
                "items" : [ 
                    {
                        "name" : "Fish Cake Soup (Lunch)",
                        "description" : "Fish cake with radish, glass noodles, and scallions.",
                        "price" : null
                    }, 
                    {
                        "name" : "Beef Short Rib Stew (Lunch)",
                        "description" : "With radish, glass noodles, scallions, and eggs.",
                        "price" : null
                    }, 
                    {
                        "name" : "Korean Gnocchi Soup (Lunch)",
                        "description" : "Korean potato pasta with bean sprouts, squash with eggs, and scallions.",
                        "price" : null
                    }
                ]
            }, 
            {
                "name" : "Rice Dishes",
                "items" : [ 
                    {
                        "name" : "Bibimbop",
                        "description" : "Build your own rice bowl. A bed of rice with spinach, mushroom, radish, julienned carrots, bean sprouts, quinoa and assorted vegetables on top. Topped with your choice of protein and fried egg. Served warm.",
                        "price" : null
                    }, 
                    {
                        "name" : "Kimchi Fried Rice (Lunch)",
                        "description" : "With sunny side up fried egg.",
                        "price" : null
                    }, 
                    {
                        "name" : "Jhap Chae Fried Rice (Lunch)",
                        "description" : "With vegetarian jhap chae and sunny side up fried egg.",
                        "price" : null
                    }
                ]
            }
        ]
    }
}

Теперь мой вопрос: должен ли я разделить вышеуказанный набор данных и создать отдельные коллекции для меню, разделов и элементов или не должен разделяться.

В моем приложении есть еще одна функция, в рамках которой пользователи могут пометить элементы как избранные, поэтому в этом случае мне нужно будет сохранить информацию в другой коллекции, столбцы которой будут "user_id" и "item_id", ноесли мы не разделим набор данных, как я могу получить идентификатор элемента в качестве первичного ключа.

...