首页 > 解决方案 > 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]
    }

这里appointmentsresources是不同的集合,每个集合中都有示例文档。

第二种方法:

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是计算约会的长度,它的开始和结束时间。

我们需要能够按照以下方式最有效地执行查询:

资源可以是任何东西,例如医生、教练、房间……

所以我的问题是,当涉及到 mongodb 查询时,哪一个更有效/可行?

标签: databasemongodbnosqlschedulerscheduling

解决方案


推荐阅读