I'm trying to find out how to do an specific query with mongoose. I have in mongodb something like this:
"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"
. 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.
which is returning []
null because their are no records of this timeperiod
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} });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.