【发布时间】:2021-07-01 06:32:18
【问题描述】:
我是新手编码员。我的学习项目是时间表。
我想打印一份预订清单,例如 2021-04-06。
但不仅是 2021-04-06。
所有预订日期均已打印。
全部失败...
我使用 NodeJS、express、mongoDB、mongoose。
帮帮我。
User Schema({
name: user1
clients: [
client1,
client2
]
});
Client Schema({
name: client1
phone: 00000000,
gender: 1,
reservation:[
{
date: 2021-04-06T00:00:00.000Z,
time: "14:00"
cancel: "off",
noshow: "on",
},
{
date: 2021-04-10T00:00:00.000Z,
time: "14:00"
cancel: "off",
noshow: "off",
}
],
memo: String,
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
}
},
{
name: client2
phone: 00000002,
gender: 0,
reservation:[
{
date: 2021-04-06T00:00:00.000Z,
time: "10:00"
note: "first"
cancel: "off",
noshow: "on",
},
{
date: 2021-04-12T00:00:00.000Z,
time: "14:00"
note: "second"
createdAt: Date,
cancel: "off",
noshow: "off",
}
],
memo: String,
user: user1
})
【问题讨论】:
-
您的架构与屏幕截图中的查询不匹配。是
reservation.date还是reserve.date? -
请不要粘贴截图,提供格式化文本的代码。见meta.stackoverflow.com/a/285557/3027266
-
每当需要处理日期和时间时,我推荐moment.js 库。它让您的生活更轻松。
-
为什么将数据和时间值存储在不同的字段中?最好只使用一个字段,
Date对象具有日期和时间组件。 -
谢谢。它在照片中的显示方式有所不同,但实际上它被统一为保护区。我使 html 标记输入更容易,我将时间和日期分开。最好把它们结合起来,所以我来做。
标签: node.js mongodb mongoose mongodb-query aggregation-framework