0

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} });
1
  • your query seem correct. please check your queryDate value Commented Feb 17, 2017 at 5:17

1 Answer 1

1

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} });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.