What is the best way to design the mongodb with events invites?

I have a project where users can invite other users to an event.

What is the best way to design the mongodb document fields?

Like this?

Event invites

{
    "_id" : "nGWEkXJR3oLNbEugE",
    "userId" : "v4b7cSa3uHqDk4Nm9",
    "invitedId" : [ 
        "TTHyxmmpdqzpmGttc", 
        "FjoBeedAQvJYSxgAs"
    ]
,
    "invitedIdApproved" : [ 
        "2rwr23r23r23r23r2", 
        "23r23r23r23r23r23r"
    ]
,
    "invitedIdDisclined" : [ 
        "23r23f23rf23f23f", 
        "23f23f23f23f23f23
    ]

}

And also have the same fields in the user document like

Event invites

{
    "userId" : "v4b7cSa3uHqDk4Nm9",
    "invitedId" : [ 
        "neweventinviteID"
    ]
,
    "invitedIdApproved" : [ 
        "nGWEkXJR3oLNbEugE", 
    ]
,
    "invitedIdDisclined" : [ 
        "23r23f23rf23f23f", 

    ]

}

Can you describe the use case a bit more, please? For example, why are you tracking the invites? What is significant about the Approved vs Disclined decision?

(Btw, Approved and Disclined may be the wrong terms to use here. Approved implies someone else granting permission to join the event. You may have meant Accepted and Declined.)

1 Like

Case:

  1. I want to invite 10 people to a MTB trip
  2. I Create a MTB event
  3. I click a invite people button on the event
  4. There will come a liste of all my contacts in the system
  5. I will check (checkbox right side of all contacts) the people I want to invite
  6. On the event there will be a list with invited people and a list with people that can come and a list with people that can’t come

Just have an object with their decisions saved in another responses collection

{
dateCreated,
userId,
eventId,
decision,
note
}

Then people if needed can respond, change their minds, you just do a final query to get the latest date created for a particular user/event but you get to save a rich history and don’t have to worry about updating user records, events etc

This allows you to track easily people that originally signed up but later canceled etc; or originally declined but after a promotion switched etc

1 Like

For the event, it can have an array of invitees that only you edit, but the results of that can come from the more event sourced view query

Since this is all related to the event, I’d probably start with just an “invites” field on the event object in your events collection.

Example event:

{
_id: "xyz",
name: "foo",
createDate: "Tue Apr 17 2018 17:53:43 GMT-0400 (EDT)",
<other event fields...>,
invitations: [
  {
    recipient: "joe@example.com OR maybe USERID",
    invitedBy: "USERID123",
    invitedByEmail: "sally@example.com",
    invitedByName: "Sally Smith",
    inviteDate: "Tue Apr 17 2018 17:53:43 GMT-0400 (EDT)",
    acceptedDate: "Tue Apr 17 2018 17:54:43 GMT-0400 (EDT)",
    accepted: true,
    msg: "Thanks for the invite!",
    ...
  }
]

If you need to do more complex things with this data then it may warrant its own collection. But for just displaying a report on the event info page then probably this is all you need.

1 Like