A
A
Arman2015-02-25 12:28:20
PHP
Arman, 2015-02-25 12:28:20

How to properly organize free/busy/reserve statuses in time periods on mongodb?

There are models in the database, you need to make statuses for them: free, busy and reserve.
Search (selection) interface:
- indicate dates from and to
- indicate the checkbox "including the reserve"
Mongo does not know how to do joins, what is the right thing to do here?
Store in date array? But how do you sample?
Let's say one record has
dates field/data: [
[2015-01-01, 2015-01-07],
[2015-02-01, 2015-02-07],
[2015-06-01, 2015-06-07 , 'reserv'],
[2015-09-01, 2015-09-17],
]
If the date is in the array and there is no "reserv" label, it is busy,
If there is a "reserv" label, then reserve
If there is no period at all, then free.
MongoDB should take the first value from the array, check if the period is there or not AND if there is a label or not. If you do not fall into any period, then the record must be returned.
Is there any operator in mongodb that walks through an array in a similar way? Or maybe there is another way to store all this and make a selection?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Huseynov, 2015-02-25
@Arik

Is there any operator in mongodb that walks through an array in a similar way?

Yes, but even simpler: write a query to the array itself. Monga will go through all the elements and check if at least one of them satisfies the specified conditions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question