javascript - MongoDb 过滤器获取两个日期之间的对象
问题描述
我正在尝试使用 MongoDB 在两个日期之间获取通知;两个日期之间有 7 天,并使用下面的函数获取数据,但我总是错误代码 500,知道如何解决吗?
下面添加了示例数据。
功能
exports.getNotifications = async (req, res) => {
try {
const notifications = await notification.find({
createdAt: { $gte: ISODate(date), $lt: ISODate(expires) },
});
return res.status(200).json({ notifications });
} catch (error) {
return res.status(500).json({
...error,
});
}
};
样本数据
{
"_id": {
"$oid": "613200ad493dae19e881e031"
},
"date": {
"$date": "2021-09-03T11:01:47.972Z"
},
"expireDate": {
"$date": "2021-09-10T11:01:47.972Z"
},
"seenBy": [],
"title": "Social Karanlık Mod!",
"coverImage": "https://www.linkpicture.com/q/Karanlık-Mod-1.png",
"actionType": "basic",
"context": "Profil sekmesindeki butondan karanlık ve aydınlık mod arasında geçiş yapabilirsiniz!",
"__v": 0
}
解决方案
推荐阅读
- qml - 无法在 TreeView 中设置 selectionMode
- sql - 根据逗号分隔值更新
- xml - 具有一个元素的 XSD 在另一个重复元素之间出现一次(以任何顺序)
- java - Java进程中的OutOfMemoryException,但Used Heap大约是Used Size的一半
- javascript - 如何让 d3.zoom 为内联 svg 工作?
- c# - Dotnet 服务终身 DI
- javascript - 带有图像幻灯片的模态和反应
- amazon-web-services - AWS:FSx 资源对 Windows Server 中的网络发现不可见
- python - 如何编写无服务器 AWS lambda 函数,该函数将使用 wget 下载 linux 第三方应用程序,然后从该应用程序执行命令?
- lightningchart - 向闪电图添加按钮