我是MongoDB的新手。我正在使用Express,mongoose,nodejs编写REST api。 我想获取两个日期之间的所有价格(集合)。在mongoDB中,我的日期保存为“ 2016-01-05 00:00:00”。而我输入的开始日期和结束日期的格式为“ 05-01-2016 0.00”(字符串)。
要在两个日期之间获取数据,我正在使用以下mongo查询:
Public cVal
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim LastRow
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
t1 = TimeValue(CStr(Cells(i, "D").Value))
t2 = TimeValue(CStr(Cells(i, "E").Value))
t3 = TimeValue(CStr(Cells(i, "F").Value))
'input First Response time
If Hour(t2) - Hour(t1) = 0 Then
Cells(i, "G").Value = Round((Minute(t2) - Minute(t1)) / 60, 2)
Else
Cells(i, "G").Value = Hour(t2) - Hour(t1) + Round((Minute(t2) - Minute(t1)) / 60, 2)
End If
'input Elapsed Time
If Hour(t3) - Hour(t1) = 0 Then
Cells(i, "H").Value = Round((Minute(t3) - Minute(t1)) / 60, 2) '- Cells(i, "J").Value - Cells(i, "J").Value
Else
Cells(i, "H").Value = Hour(t3) - Hour(t1) + Round((Minute(t3) - Minute(t1)) / 60, 2) '- Cells(i, "J").Value
End If
Next i
Target.Offset(1).Select
End Sub
但出现以下错误:
let startDate = moment(req.params.startdate, "DD-MM-YYYY hh:mm:ss").format("YYYY-MM-DD hh:mm:ss")
let endtDate = moment(req.params.endtdate, "DD-MM-YYYY hh:mm:ss").format("YYYY-MM-DD hh:mm:ss")
Price.find({
date: {
$gte: startDate,
$lte: endtDate
}
})
.exec()
.then(result => {
res.status(200).json(result)
})
.catch(err => {
res.status(500).json({
error: err
})
})
如果我做错了事,请让我知道。