Reputation: 1079
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} });
Upvotes: 0
Views: 89
Reputation: 6796
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} });
Upvotes: 1