Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-39885

Should I split the sub documents in separate collections or not, in MongoDB?

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Server Triage

      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.

            Assignee:
            backlog-server-triage [HELP ONLY] Backlog - Triage Team
            Reporter:
            abhilash.lohar Abhilash Lohar
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: