javascript - CastError:在路径的起息日转换为日期失败
问题描述
我正在尝试在我用 Mongo 开发的数据库中进行查询,我们有模式 Examen(或考试),我们需要找到两个日期之间的所有考试。我的系统可以获取两个日期并使用此表单进行查询(我也使用 Moment 以获得正确的格式)
这是我从网站上得到的查询
{ "examDate": { "$gt": { "$date": "1556686800000" }, "$lt": { "$date": "1559192400000"} } }
当我在 Studio3T 中运行此查询时,它可以正常工作,但在网站中出现错误:
CastError:模型“Examen”的路径“examDate”处值“{'$date':'1559192400000'}”的转换为日期失败
我也尝试使用 ISO 格式更改“$date”格式,但没有成功。奇怪的是,查询在 Studio3T 中正常工作,但使用 Mongo db.find() 函数却不能这样工作。
//this is how I make the find function for my schema
Examen.find((query), (err, info_examen) => {
if (err) return res.status(500).send({ message: `Error: ${err}` })
if (!info_examen) return res.status(404).send({ message: `there is no data` })
res.status(200).send({ info_examen })
})
我希望得到结果(info_examen)以便对数据进行统计。
解决方案
推荐阅读
- linux - 在 shell 脚本中检查连接
- python - f-strings 适用于 python IDLE 但不适用于 Sublime Text
- android - Android Dagger Hilt:我们需要 ViewModel 的范围注释吗?
- python - 使用 matplotlib 绘制趋势线
- java - 使用 Azure 构建管道时,从 JaCoCo 中排除多模块 maven 项目中的测试目录
- java - Spinner First Item Devider android
- python - 如何在 Django 的模板代码块中访问列表的长度?
- clojurescript - 如何在 ClojureScript 中获取“导航器”对象?
- c# - 如何按前缀编号然后按字母顺序对字符串列表进行排序
- javascript - 为什么我的最新代码覆盖了我的其余代码