โ05-16-2019 07:05 AM
Hi,
I am trying to filter the records from MongoDB Select snap using date filter but somehow it is not working. I am using below expression in condition. Please suggest if I am doing something wrong:
{$and:[{โetl_dateโ:{$gte:โ2019-05-15T00:00:00.000โ}},{โetl_dateโ:{$lte:โ2019-05-15T23:59:00.000โ}}]}
Thanks
Aditya
โ05-16-2019 11:31 AM
I am assuming that when you say it is not working, it is giving syntax error. I tried the exact same syntax on my local mongo db instance, it gives the syntax error with MongoDB compass which is a front end tool to connect to MongoDB directly.
I think it it does not like the letter โTโ that separates the date from the time component. You can just remove it and try, it should work.
For example, in my table, I had a column create_time that I used as shown below:
{$and:[{โcreate_timeโ:{$gte:โ2019-02-12 20:53:31.000โ}}, {โcreate_timeโ:{$lte:โ2019-02-12 20:53:31.000โ}}]}
Hope this helps.
โ05-16-2019 11:56 AM
Try the following:
{โINSERT_TIMESTAMPโ: {โ$gteโ: ISODate(โ2018-09-01โ), โ$lteโ: ISODate(โ2018-12-01โ)}}
Based on MongoDB documentation it should be in the above format and the API is expecting the same from Snap
โ05-16-2019 02:05 PM
Thanks, it worked.