The requirement is to query for a period of time, some of the schedule is repeated each year (month, day), how to get the schedule within a find?
The repetition means that the addition of the May 1 schedule of this year, I query next April-May schedule, still can find his
I hope I can give you a clue
Reply content:
The requirement is to query for a period of time, some of the schedule is repeated each year (month, day), how to get the schedule within a find?
The repetition means that the addition of the May 1 schedule of this year, I query next April-May schedule, still can find his
I hope I can give you a clue
If there is such a need, it should be stored in the data when the number of fields to express the "month" and "Day" information, which does not matter to PHP, but the design of MONGODB data structure.
For example, add a field:
{ "repeat_date": { "month": 5, "day": 1 }}
When you query, you can write:
// 找到所有月份为 5 的db.foo.find({"repeat_date.month": 5})
This repeat_date
field is added only on the yearly recurring schedule and does not need to be added for non-recurring schedules.
If you need to identify all the schedules in a certain time period, including the yearly recurring schedule, you can query:
// 假设每个日程都有一个类型为 `ISODate` 的 `date` 字段表示日程发生在哪一天db.schedule.find({ $or: [ { date: { $gte: new Date("2014-03-01 00:00:00"), $lt: new Date("2014-05-01 00:00:00") }, }, { "repeat_date.month": { $gte: 3, $lt: 5 } } ]})