I am trying to fetch the records that has the "effectiveDateOfAction" field greater than Oct'2017. Please find the below 3 records.
{
"_id": "TRAN001",
"_rev": "13-59a53069c1ebd6ecfc23ca1dea0ba28f",
"effectiveDateOfAction": "10-30-2018",
"employeeName": "Kumar,Vinoth",
"transferReportID": "TRAN001",
"~version": "76:0"
}
{
"_id": "TRAN001",
"_rev": "12-c320c61168f5d6d020f971124cb395f2",
"effectiveDateOfAction": "05-10-2018",
"employeeName": "Vinoth",
"transferReportID": "TRAN002",
"~version": "77:0"
}
{
"_id": "TRAN003",
"_rev": "16-567a15e9ea7e2349d4c24816e7eafda3",
"effectiveDateOfAction": "10-20-2017",
"employeeName": "Kumar",
"transferReportID": "TRAN003",
"~version": "78:0"
}
Please find my query below which i tried.I am checking using Project Fauxton.
{"selector": {"$and": [{"transferReportID": {"$ne": null}},{"effectiveDateOfAction": {"$gt": "10-31-2017"}}]}}
Please help me getting the correct query.
As there is no native date type in JSON, it's important to store dates in a format that makes sense at query time. The "Month-Day-Year" format may be useful when rendering dates for a US audience but it makes little sense for querying.
I would suggest the "YYYY-MM-DD" format e.g "2018-10-30". This stores the same data as before but the sort order happens to be in date order, because years are longer than months and months are longer than days.
You can then use a query using the "$gte" operator:
This reads as "fetch documents whose 'effectiveDateOfAction' field is greater than or equal to 1st October 2018'.
See this blog post on how to store and query dates in CouchDB.