我们有两种不同的方法来使用mongodb实现预约系统。
在这里,我们只有一个集合,而约定日期是集合中的键。每个日期键都包含多个JSON对象,表示同一天不同的约会。
注意:
没有超过1天的约会,我们有
我们需要以最有效的方式执行查询,例如:
- 获取特定资源ID的所有约会 - 获取资源在两个不同日期之间的约会 - 获取用户在不同日期之间的约会 - 取消/删除约会
资源可以是任何东西,例如医生、教练、房间等等。
所以我的问题是,对于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查询,哪种方法更有效/可行?
userId
进行查询会很丑吗?@Natixco - riadrifai