当我从cmd查询时,我得到的结果是日期小于“ 2016-01-05”,但是当我通过猫鼬查询时,它无法将日期转换为正确的格式,而是在mongo服务器中正在转换为$ lte:new Date(1452384000000),因此无法查询。
我已经在StackOverflow上搜索了可能的错误但没有帮助。我也尝试过起诉但没有帮助
使用命令行
db.prices.find({date:{$lt:'2016-01-10'}})
In server, the command looks like the above and I am getting the result.
下面是猫鼬的命令,结果为空
let timeFrame = (req,res)=>{
var start = new Date(req.params.startDate);
var end = new Date(req.params.endDate);
if (start < end)
{
PriceModel.find({'date':{$lte:end}}).exec((err,result)=>{
console.log("Result is ",result);
})
}
else if (start.valueOf()==end.valueOf()) {
console.log("both are equal");
}
else{
console.log("Please enter date in reverse way");
}
}
In mongoose server it looks like below
2019-04-28T19:13:52.543+0530 I COMMAND [conn2] command slicePay.prices command: find { find: "prices", filter: { date:
{ $lte: new Date(1452384000000) } }, projection: {} } planSummary: COLLSCAN keysExamined:0 docsExamined:339507 cursorExh
austed:1 keyUpdates:0 writeConflicts:0 numYields:2652 nreturned:0 reslen:121 locks:{ Global: { acquireCount: { r: 5306 }
}, MMAPV1Journal: { acquireCount: { r: 2653 } }, Database: { acquireCount: { r: 2653 } }, Collection: { acquireCount: {
values for test
{ "_id" : ObjectId("5cc558827a769d9983624219"), "date" : "2016-01-05 00:00:00", "symbol" : "WLTW", "open" : 123.43, "clo
se" : 125.839996, "low" : 122.309998, "high" : 126.25, "volume" : 2163600 }
{ "_id" : ObjectId("5cc558827a769d998362421a"), "date" : "2016-01-06 00:00:00", "symbol" : "WLTW", "open" : 125.239998,
"close" : 119.980003, "low" : 119.940002, "high" : 125.540001, "volume" : 2386400 }
{ "_id" : ObjectId("5cc558827a769d998362421b"), "date" : "2016-01-08 00:00:00", "symbol" : "WLTW", "open" : 115.480003,
"close" : 116.620003, "low" : 113.5, "high" : 117.440002, "volume" : 2006300 }
{ "_id" : ObjectId("5cc558827a769d998362421c"), "date" : "2016-01-07 00:00:00", "symbol" : "WLTW", "open" : 116.379997,
"close" : 114.949997, "low" : 114.93, "high" : 119.739998, "volume" : 2489500 }
{ "_id" : ObjectId("5cc558827a769d9983624314"), "date" : "2010-01-04", "symbol" : "A", "open" : 31.389999, "close" : 31.
300001, "low" : 31.13, "high" : 31.630001, "volume" : 3815500 }
{ "_id" : ObjectId("5cc558827a769d9983624315"), "date" : "2010-01-04", "symbol" : "AAL", "open" : 4.84, "close" : 4.77,
"low" : 4.66, "high" : 4.94, "volume" : 9837300 }
{ "_id" : ObjectId("5cc558827a769d9983624316"), "date" : "2010-01-04", "symbol" : "AAP", "open" : 40.700001, "close" : 4
0.380001, "low" : 40.360001, "high" : 41.040001, "volume" : 1701700 }
{ "_id" : ObjectId("5cc558827a769d9983624317"), "date" : "2010-01-04", "symbol" : "AAPL", "open" : 213.429998, "close" :
214.009998, "low" : 212.380001, "high" : 214.499996, "volume" : 123432400 }
{ "_id" : ObjectId("5cc558827a769d9983624318"), "date" : "2010-01-04", "symbol" : "ABC", "open" : 26.290001, "close" : 2
6.629999, "low" : 26.139999, "high" : 26.690001, "volume" : 2455900 }
{ "_id" : ObjectId("5cc558827a769d9983624319"), "date" : "2010-01-04", "symbol" : "ABT", "open" : 54.189953, "close" : 5
4.459951, "low" : 53.919951, "high" : 54.559954, "volume" : 10829000 }
{ "_id" : ObjectId("5cc558827a769d998362431a"), "date" : "2010-01-04", "symbol" : "ACN", "open" : 41.52, "close" : 42.07
, "low" : 41.5, "high" : 42.200001, "volume" : 3650100 }
{ "_id" : ObjectId("5cc558827a769d998362431b"), "date" : "2010-01-04", "symbol" : "ADBE", "open" : 36.650002, "close" :
37.09, "low" : 36.650002, "high" : 37.299999, "volume" : 4710200 }
{ "_id" : ObjectId("5cc558827a769d998362431c"), "date" : "2010-01-04", "symbol" : "ADI", "open" : 31.790001, "close" : 3
1.67, "low" : 31.610001, "high" : 32.189999, "volume" : 2102700 }
{ "_id" : ObjectId("5cc558827a769d998362431d"), "date" : "2010-01-04", "symbol" : "ADM", "open" : 31.48, "close" : 31.46
9999, "low" : 31.33, "high" : 31.84, "volume" : 3472500 }
{ "_id" : ObjectId("5cc558827a769d998362431e"), "date" : "2010-01-04", "symbol" : "ADP", "open" : 43.54, "close" : 42.83
0002, "low" : 42.700002, "high" : 43.54, "volume" : 3930100 }
{ "_id" : ObjectId("5cc558827a769d998362431f"), "date" : "2010-01-04", "symbol" : "ADS", "open" : 65, "close" : 65.88999
9, "low" : 64.959999, "high" : 66, "volume" : 794300 }
{ "_id" : ObjectId("5cc558827a769d9983624320"), "date" : "2010-01-04", "symbol" : "ADSK", "open" : 25.610001, "close" :
25.67, "low" : 25.610001, "high" : 25.83, "volume" : 2228600 }
{ "_id" : ObjectId("5cc558827a769d9983624321"), "date" : "2010-01-04", "symbol" : "AEE", "open" : 28.030001, "close" : 2
7.76, "low" : 27.690001, "high" : 28.27, "volume" : 1299300 }
{ "_id" : ObjectId("5cc558827a769d9983624322"), "date" : "2010-01-04", "symbol" : "AEP", "open" : 35.099998, "close" : 3
4.939999, "low" : 34.799999, "high" : 36, "volume" : 4076600 }
{ "_id" : ObjectId("5cc558827a769d9983624323"), "date" : "2010-01-04", "symbol" : "AES", "open" : 13.38, "close" : 13.67
, "low" : 13.38, "high" : 13.7, "volume" : 4597600 }
答案 0 :(得分:1)
答案 1 :(得分:0)
尝试
var start = new Date(req.params.startDate);
var end = new Date(req.params.endDate);
收件人
var start = req.params.startDate;
var end = req.params.endDate;
为什么?:
我认为,在您的mongodb中,列date
的数据类型不是Date,可以是字符串。
如果是日期类型,则可以与MongoDB/Mongoose querying at a specific date?