Suppose the sample documents in Mongodb database are as follows:
{ "date" : ISODate("2015-11-09T05:58:19.474Z") }
{ "date" : ISODate("2014-10-25T07:30:00.241Z") }
{ "date" : ISODate("2015-11-30T15:24:00.251Z") }
{ "date" : ISODate("2012-01-10T18:36:00.101Z") }
Expected:
{ "date" : ISODate("2015-11-09T05:58:19.474Z") }
{ "date" : ISODate("2014-10-25T07:30:00.241Z") }
Iam interested in finding the documents whose time in "date" field is between 04:15 and 07:40 irrespective of day,month and year. Indirectly query has to match any "YYYY-MM-DDT" in date field.
My approach would be, query all the documents within presumed duration of dates from node and then for each document that matched the query, compare the "date" field of document with "yyyy-MM-DDT"+"required_time" ("YYYY-MM-DD is copied from each document's "date field" to compare by converting into moment() and get month,date and year") using moment.js module.
Is there any way to query to directly get the same results?
Note: I am using nodejs to connect to mongodb
This question is based on Mongodb : Query based on time in ISODate format.