【发布时间】:2021-02-13 17:24:22
【问题描述】:
在这里,我的日期(即 updatedAt)为 "2020-10-28T09:20:14.335Z" 和 "2020-10-30T09:20:35.086Z" 。如何过滤特定日期的数据(例如:2020-10-28)。
来自服务器的数据
[
{
"_id": "5f9bdace778082303c859248",
"createdAt": "2020-10-28T09:20:14.335Z",
"updatedAt": "2020-10-28T09:20:14.335Z",
"__v": 0
},
{
"_id": "5f9bdae3778082303c859249",
"createdAt": "2020-10-30T09:20:35.086Z",
"updatedAt": "2020-10-30T09:20:35.086Z",
"__v": 0
}
]
路由:它给出了空数组,如何使它工作?
Attendance.find({ "updatedAt": { "$gte": "2020-10-28", "$lte": "2020-10-28" } })
.then(data => res.json(data))
.catch(err => res.status(400).json('Error: ' + err));
路线:但这行得通
Attendance.find({ "updatedAt": { "$gte": "2020-10-28T09:20:14.335Z", "$lte": "2020-10-28T09:20:14.335Z" } })
.then(data => res.json(data))
.catch(err => res.status(400).json('Error: ' + err));
【问题讨论】:
标签: mongodb express mongoose mern