[英]Node js mongoose querying by dates
I'm trying to find out how to do an specific query with mongoose. 我试图找出如何用猫鼬做特定的查询。 I have in mongodb something like this:
我在mongodb中有这样的东西:
"startDateTime" : ISODate("2017-03-22T00:00:00.000Z"),
"endDateTime" : ISODate("2017-03-27T00:00:00.000Z"),
I want to get all the documents which that specific date is within that "startDateTime"
and "endDateTime"
. 我想获取所有特定日期在
"startDateTime"
和"endDateTime"
内的文档。 I have tried as follows but it returns no results. 我尝试了如下,但没有返回结果。
var criteria = {};
criteria.$and = [];
criteria.$and.push({ startDateTime: {$gte: queryDate} });
criteria.$and.push({ endDateTime: {$lte: queryDate} });
the queryDate
is Same for both of the conditions if your queryDate
= 17-02-2016
you are searching for the records greater then that timeperiod and as well as lesser then that time period. 如果
queryDate
= 17-02-2016
,则两个条件的queryDate
都相同。您要搜索的记录大于该时间段,而小于该时间段。
which is returning []
null because their are no records of this timeperiod 返回
[]
null的原因是他们没有此时间段的记录
criteria.$and.push({ startDateTime: {$gte: '17-02-2016'} });
criteria.$and.push({ endDateTime: {$lte: '17-02-2016'} });
var criteria = {};
criteria.$and = [];
criteria.$and.push({ startDateTime: {$gte: queryDate} });
criteria.$and.push({ endDateTime: {$lte: queryDate} });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.