4

I'd like to allow my users to setup a schedule for their events. It could be a single day, or for convenience I'd like to allow them to specify a reoccurring event (similar to an Outlook appointment).

Storing a single day would be pretty easy, but how could I store and query a reoccurring event? I don't need to do times, as I'd just store that separately, and if they needed a different time I'd just have them create another event. So no: Every Wednesday at 5 and Thursday at 3.

Examples:

Every mon, tues, wed, thu, fri, every week

Every wed every week

Every second tuesday of the month

I asked this a few years ago: How can I store and query schedule data? but it was using a SQL solution (SQL Server). I want to use Mongo though so a port is in order.

Community
  • 1
  • 1
rball
  • 6,925
  • 7
  • 49
  • 77

1 Answers1

3

How about storing the original date and information about the recurrence? Its an unlimited field for experiments and you can invent a "recurring event format" of your own. For example:

event : {
   date: 17 May 2012 22.45, 
   recurring: "+2d"  # meaning, every second day after the date
}
Zaur Nasibov
  • 22,280
  • 12
  • 56
  • 83
  • This is kind of the approach I am using in my mongo project; Using identifiers that can be matched against. You can filter to a certain extent, and then it might involve some client-side filtering. In python I use dateutil module to reconstruct a reoccurring date object. – jdi May 17 '12 at 20:05
  • So can you give some basic queries? I am a total mongo newb. How would I show for the next week what events are coming up? – rball May 18 '12 at 02:41
  • You can't do that via Mongo. It's business logic that should reside in the application, not in the database. – Zaur Nasibov May 18 '12 at 07:40
  • 1
    @BasicWolf: Data queries should still be on the database layer. You can't expect the app to get ALL events and then do the querying client-side. That wouldn't be a good idea. – Noel Llevares Oct 30 '12 at 03:06
  • @BasicWolf: Yes. SQL DBs can. In (strict) theory, there should be a clear separation between business logic and data layers. Mongo, however, cannot do some stuff that SQL DBs can. So, as a workaround, developers have settled into putting data query logic into their business logic. One example of this are inter-document joins. – Noel Llevares Nov 14 '12 at 05:02
  • 2
    @dashmug, I disagree, the recurring date is something from business logic, not a data layer. – Zaur Nasibov Nov 14 '12 at 07:35