mongodb - 按日期(年)在数据库中查找文档;
问题描述
我正在尝试对我的数据库进行查询,我有一个包含一些包含日期类型字段的文档的集合,我想查找日期等于我选择的年份的所有文档,最好的方法是什么做吗?
此刻我正在收到这样的文件。
facturasCtrl.filterDates = async (req, res) => {
facturas = await facturasModel.find({ date: { '$gte': req.body.date1, '$lt': req.body.date2} })
res.json(facturas);
}
//date1 = 1.1.2018 //date2 = 31.12.2018
但我认为这种方式根本不正确......有什么方法可以从某个日期找到所有文件?
解决方案
推荐阅读
- javascript - 使用 JQuery .load() 将 JSON 数据发送到 Flask 服务器
- embedded - STM32 EEPROM 仿真与 HAL_FLASH 和 HAL_FLASH_EX 驱动程序
- java - 如何使用 UssdResponseCallback 和 sendUssdRequest?
- ios - 如何从 swift Xcode 中的不同类更改 UISwitch 的值?
- excel - WorkbookOpen 事件有时不会触发 - 用于设置全局变量的事件
- python - 这些词的意思是一样的吗?
- ios - 使用单独的控制器将自定义单元格中的标签设置为数组中的名称
- c - 能够从尚未分配值的malloc'ed范围中读取它是一个安全漏洞吗?
- swiftui - 当按钮靠在一起时,SwiftUI NavigationLink 行为不正确
- python - Allennlp 德国 elmo 模型