我的数据库中有许多办公室,每个办公室都有自己的运行时间(例如:从7:00到17:00)。
我是否应该像这样存储操作时间:
{
"_id" : ObjectId("59747cfabb8dd11e30310a92"),
"name" : "CE",
"value" : "Compact Enterprise",
"operation_time_start": "7:00", -> string value
"operation_time_end": "17:00" -> string value
}或者尝试另一种方法?
发布于 2017-08-10 20:00:49
我建议使用0- 1440范围内的整数,每个数字都是一分钟的增量。这样,您就可以在查询示例中使用$gte和$lte:
{
"_id" : ObjectId("59747cfabb8dd11e30310a92"),
"name" : "CE",
"value" : "Compact Enterprise",
"operation_time_start": 420
"operation_time_end": 1020
}作为额外的建议,考虑到开放时间可以根据星期几的不同而不同,因此更好的模式可能如下所示:
{
"_id" : ObjectId("59747cfabb8dd11e30310a92"),
"name" : "CE",
"value" : "Compact Enterprise",
"operations: {
"1": {start: 420, end: 1020 }, -> operation time for dayOfWeek = 1
"2": {start: 420, end: 1020 }, -> operation time for dayOfWeek = 2
.....
}
}https://stackoverflow.com/questions/45606475
复制相似问题