database - Mongodb模式构建预约系统
问题描述
对于预约调度系统,我们有两种不同的方法,使用 mongodb。
第一种方法:
appointments:
{
resourceId: "string",
resourceType: "doc"/"nut"...,
userId: "string",
userName: "string",
startDate: "2020-05-18T16:00:00Z",
endDate: 2020-05-18T17:00:00Z
title: "string",
description: "string",
type: "string"/"off"
},
{
resourceId: "string",
resourceType: "doc"/"nut"...,
userId: "string",
userName: "string",
startDate: "2020-05-21T12:00:00Z",
endDate: 2020-05-21T12:30:00Z,
title: "string",
description: "string",
type: "string"/"off"
},
...
resources:
{
resourceId: "string",
resourceName: "string"
resourceType: "doc"/"nut"/"room",
autoApprove: true/false,
constantDaysOff: [sunnday]
},
{
resourceId: "string",
resourceName: "string"
resourceType: "doc"/"nut"/"room",
autoApprove: true/false,
constantDaysOff: [sunnday]
},
{
resourceId: "string",
resourceName: "string"
resourceType: "doc"/"nut"/"room",
autoApprove: true/false,
constantDaysOff: [sunnday]
}
这里appointments
和resources
是不同的集合,每个集合中都有示例文档。
第二种方法:
resources:
{
resourceId: "string",
resourceName: "string",
resourceType: "doc"/"nut"...,
constantDaysOff: [sunday],
2020-05-21: [
{
startDate: "2020-05-21T12:00:00Z",
endDate: 2020-05-21T12:30:00Z,
userId: "string",
userName: "string",
title: "string",
description: "string",
type: "string"/"off"
},
{
startDate: "2020-05-21T14:00:00Z",
endDate: 2020-05-21T14:30:00Z,
userId: "string",
userName: "string",
title: "string",
description: "string",
type: "string"/"off"
}
],
2020-05-22: [
{
startDate: "2020-05-22T12:00:00Z",
endDate: 2020-05-22T12:30:00Z,
userId: "string",
userName: "string",
title: "string",
description: "string",
type: "string"/"off"
},
{
startDate: "2020-05-22T14:00:00Z",
endDate: 2020-05-22T14:30:00Z,
userId: "string",
userName: "string",
title: "string",
description: "string",
type: "string"/"off"
}
]
...
}
这里我们只有一个集合,约会日期是集合中的关键。每个日期键将包含多个 json 对象,表示同一天的不同约会。
笔记:
没有超过 1 天的约会,我们有startDate
并且endDate
是计算约会的长度,它的开始和结束时间。
我们需要能够按照以下方式最有效地执行查询:
- 获取特定资源 ID 的所有约会
- 在两个不同的日期之间获取资源的约会
- 在不同日期之间为用户获取约会
- 取消/删除约会
资源可以是任何东西,例如医生、教练、房间……
所以我的问题是,当涉及到 mongodb 查询时,哪一个更有效/可行?
解决方案
推荐阅读
- postgresql - 嵌套 JSONB 列的通配符搜索,包括数字数据类型
- serverless-framework - AWS EventBridge - 放置一个延迟事件
- ruby-on-rails - 如何在 spree 中注册新的 finder 课程?
- android - 基于 Big Sur 的 Ionic Capacitor Android 构建
- vba - VBA MS ACCESS 如何打开在特定时间范围内创建的文件?
- r - 在 R 中的数据框的两列中查找缺失的匹配项
- stm32 - STM32 链接器脚本仅用于 FLASH 中的启动脚本,其他所有内容均来自 RAM
- vba - 合并几个 Word 文件,使用文件名作为 Heading1,并降级(嵌入)标题
- angular - PWA 应用程序的移动设备上的实时重新加载功能
- javascript - TypeError:findTag.delete 不是函数