[SERVER-39885] Should I split the sub documents in separate collections or not, in MongoDB? Created: 28/Feb/19  Updated: 06/Dec/22  Resolved: 28/Feb/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Abhilash Lohar Assignee: Backlog - Triage Team
Resolution: Done Votes: 0
Labels: questions
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Triage
Participants:

 Description   

I have the following data set in 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
                    }
                ]
            }
        ]
    }
}

Now my question is: Should I split the above data set and create separate collections for menus, sections & items or should not split.

There is an another feature in my application, in which users can mark the items as favourite, so in that case I will need to save the information in another collection whose columns will be "user_id" & "item_id", but if we not split the data set how can I get item id as primary key.



 Comments   
Comment by Eric Sedor [ 28/Feb/19 ]

Hi Abhilash, the SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag.

Comment by Danny Hatcher (Inactive) [ 28/Feb/19 ]

Program Management Note

  • Status set to Needs Verification after move.
Comment by Abhilash Lohar [ 28/Feb/19 ]

I want search business by item name, what should be my query.

Anybody can help me?

Generated at Thu Feb 08 04:53:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.