I am currently experimenting with Node.js and MongoDB to build an app for my wedding. I am currently working on a table planner for the wedding breakfast which will work like a Trello Board. Each guest will be an item and each dinner table would act like a trello list. So when built we can just drag and drop guests from an unassigned pile to a particular trello style board which will allocate them a position at the table.
Each Breakfast table will seat multiple guests and a guest can only sit at one table. I'm getting a bit confused whether to include a 'table' as a foreign key in the guest model or vice versa.
Having the 'table' as the foreign key allows me to easily query for guests which do not currently have a table. On the other hand, having guests as foreign keys in the 'table' model lets me easily query for tables which don't yet have any guests assigned yet.
I will need to perform both of the above queries in order to update the state in React.
Below shows my Guest schema and its relationship to the table model:
const guestSchema = new mongoose.Schema({
  firstname: {
      type: String,
      required: 'Please provide the first name of the guest',
      trim: true
  },
  surname: {
      type: String,
      required: 'Please provide the surname of the guest',
      trim: true
  },
  attending: {
      type: String,
      default: 'Awaiting RSVP'
  },
  menu: {
      type: String,
      default: 'Awaiting RSVP'
  },
  allergies: {
      type: String,
      default: 'Awaiting RSVP'
  },
  table: {
      type: mongoose.Schema.ObjectId,
      ref: 'Table',
  }
});
const tableSchema = new mongoose.Schema({
  name: {
    type: String,
    required: 'Please provide the name of the table',
    trim: true
  },
  capacity: {
    type: Number,
    required: 'Please provide the capacity of the table',
  }
}); 
     
    