0

Preface: I don't have experience with rules engines, building rules, modeling rules. Therefore, I don't know what I'm doing or if what I attempted below is way off base.

I have a set of 'id's and these ids are active only at some specific time. For example the id "xyz" is active on monday and friday from 10AM to 12PM and from 6PM to 7PM. So i need to design a database to store these data( the ids and the time in which they are active ). Currently the precision is hour but later it may become minutes. Also frequent insertion and removal may happen. what is the best way to achieve this? I am using java + mongo (can use sql if necessary).

One solution is to store the data as a set of rules, but this seems very dirty: "id","days","minHour","maxHour"`

id     days    minHour    maxHour
-----------------------------------
sd3     1,2,3     1          5
sd3     4,5       6          7
fd5     1,2,3     4          5              

another solution is to :

day     hour         ids
-------------------------------------
1        1           as1,fg2,ew3
1        2           as1,fg2,dsf6,sdf34
1        .           . . . 
1        24          . . .
2        1 
2        2
.        .
.        .
7        24 

and just insert the ids in all the rows necessary.

Nithin
  • 5,470
  • 37
  • 44
  • 1
    Whatever you do, get away from CSV data by using [Junction tables](http://stackoverflow.com/a/32620163) or association tables. – Drew Jul 13 '16 at 11:41
  • @Drew I am using mongo, which has array datatype – Nithin Jul 13 '16 at 11:46
  • 1
    I came here because of the later-to-be-removed `mysql` tag. Hopefully array types in mongo use indexes. Otherwise it will suffer the same fate – Drew Jul 13 '16 at 11:48

0 Answers0