4

I'm building a Calendar based application where there are events in a calendar. Events can be recurring (daily, weekly, monthly, quarterly, bi-annually and annually).

Each event document has a default name, defaultDate and description but also contains an array (userData) of objects that are associated with each user (userDate, userDescription). Although the events are centralised, some users have their own userDate which isn't the default and each user is able to set their own userDescription for the event. That's why the userData object exists.

To clarify, the event document looks something like this:

{
    _id: '1234567',
    name: 'Event One',
    description: 'This is the default description',
    defaultDate: '2017-02-15T12:00:00.000Z',
    userData: [
        { 
            userId: '8765432',
            userDate: '2017-06-10T12:00:00.000Z',    
            userDescription: 'My personalised description',
        },
        { 
            userId: '461938',
            userDate: '2017-03-21T12:00:00.000Z',    
            userDescription: 'I have a description too!',
        },       
    ]
}

I'm trying to work out the best way to handle storing recurrences of these events when they are created. When the event is edited it needs to edit all other copies of the event too. There will never be a scenario where a single event needs to be edited but the recurrances are left untouched.

When the events are created, I have a HTML select which asks if the event is recurring and has the following options: none, daily, weekly, monthly, quarterly, bi-annually, annually

If anyone can advise the best way to create recurring copies of these events I would appreciate it!

Sean
  • 2,609
  • 1
  • 18
  • 34
  • Would any of the patterns from http://stackoverflow.com/questions/5183630/calendar-recurring-repeating-events-best-storage-method work for you? – Alex Blex Feb 13 '17 at 13:56
  • I'm not 100% sure. Because they are using mySQL I don't fully understand how they work and if they are applicable to Mongo. I was hoping someone may have done this with MongoDB and have a solution that worked for them – Sean Feb 13 '17 at 14:20
  • These are generic patterns to solve the generic problem. There are several ways to deal with recurring events, each has pros and cons. Nothing specific to SQL or mongo. Implementations would differ of course, but if you are asking for the best way, you need to choose which one is the best for you. Otherwise the question is too broad. – Alex Blex Feb 13 '17 at 14:31
  • The solutions on that page are specifically using SQL joins though right? How can I apply that solution to a NoSQL database? I need to provide my calendar with an array of events, so I need to work out how to store recurring events in a format that allows me to do that - I don't think the question is too broad – Sean Feb 13 '17 at 15:58
  • Joins is the simplest part. It is 1:n relation in all cases, and can be easily converted into in-document array, or used with aggregation's lookup. The real problem is cost of interval calculations vs cost of CRUD. It is very well described in the comments there. – Alex Blex Feb 13 '17 at 16:19

0 Answers0