What schema for this project?

So I want to create a little weekly meal planning application but I’m currently stuck at the creation of the schemas for the database.

  • There are multiple users
  • meals that stores the users that eat this meal (not every user eats every meal)
  • meal plan: one a week. lunch and dinner for every user. monday to sunday

Hi @Jelly ,

When designing data for MongoDB ita not enough to just mentioned the data the user stores but we need to understand how the application uses and present the data.

When a user login to the app what data should he see?

  • A calendar with the meals.placed on dates in the month?
  • A list of his meals and the details?
  • his personal information and summary?

Based on this data it will be easier to determine what data should be stored together, reference or duplicated for ease of queries and updates.

I also suggest to read :

Thanks
Pavel

Well it’s not really a calendar. In the frontend it would be a table that represents an entire week of meals separated by user and daytime. For example:

Plan 1 (week 1){
  monday{
    lunch{
      user1{
        meal1
      },
      user2{
        meal1
      }
    }
    dinner{
      user1{
        meal2
      },
      user2{
        meal3
      }
    }
  },
  tuesday{
    .....
  }
},
Plan 2 (week 2){
  .......
}

Hi @Jelly ,

So it sounds like a weekly document storing that information with user meals as a subdocument/array of subdocuments is beneficial for the application presenting layer.

//Week1
{ _id : ...,
week : "week1",
startdate : ISODate()
...
Schedule : [ { "day" : "Monday", lunch: [ { user : user1, meal : { id : [<mealId>, title : ... }}, {user: ."user2" ...} ... , Dinner: ... ] ,
{"day" : "Tuesday" ... } ... ]
}
// Week2 
{ _id : ...,
week : "week2",
...
}

Now data for meals and user repo can also reside separately (duplicate only rarely changing fields in the weeks collection)

If the document is too large to for a week.maybe have a similar document only for day (7 documents a week) and combine them in the ui…

Let me know if that makes sense.

Pavel