parameters = {
"startDate": "2013-01-01T00:00:00+05:30",
"endDate": "2013-12-31T23:59:59+05:30"
}
var prom = student.find({
admissiondate: {
$gte: new Date(parameters.startDate),
$lte: new Date(parameters.endDate)
}
}, { _id: 0, admissionno: 1, firstname: 1, lastname: 1 })
#for date to isostring
var prom = student.find({
admissiondate: {
$gte: new Date(parameters.startDate).toISOString(),
$lte: new Date(parameters.endDate).toISOString()
}
}, { _id: 0, admissionno: 1, firstname: 1, lastname: 1 })
期望:一个数字(例如12)
错误:
CastError:对于模型“学生”,路径“准入日期”中的值“无效日期”的转换日期失败
RangeError:Date.toISOString()处的时间值无效
答案 0 :(得分:0)
尝试将new Date()
更改为ISODate()
var prom = student.find({
admissiondate: {
$gte: ISODate(parameters.startDate).toISOString(),
$lte: ISODate(parameters.endDate).toISOString()
}
}, { _id: 0, admissionno: 1, firstname: 1, lastname: 1 })