If the dates in your query are dynamically provided at runtime then a view may not be the right approach. You can use Cloudant Query to run dynamic queries at runtime. For example, you can create an index on your date field like so:
{
"index": {
"fields": [
"mydate"
]
},
"type": "json"
}
and then use the following selector in a Cloudant Query:
"selector": {
"$and": [
{"mydate" : { "$gt": 1506874127 }},
{"mydate": { "$lt": 1506960651 }}
]
}
I am using unix timestamps in this example.
Alternatively, you can use Cloudant Search. Create a search index in Cloudant similar to the following:
{
"_id": "_design/allDocs",
"views": {},
"language": "javascript",
"indexes": {
"byMyDate": {
"analyzer": "standard",
"index": "function (doc) {\n if (doc.mydate) {\n index(\"mydate\", doc.mydate);\n }\n}"
}
}
}
This corresponds to the following when using the Cloudant dashboard:
design doc = allDocs
index name = byMyDate
index function =
function (doc) {
if (doc.mydate) {
index("mydate", doc.mydate);
}
}
Then you can run a search using a range. For example,
https://<YOUR_INSTANCE>.cloudant.com/<YOUR_DB>/_design/allDocs/_search/byMyDate?q=mydate%3A[1506874127%20TO%201506960651]
Here the search query is:
mydate:[1506874127 TO 1506960651]
Again, I am using unix timestamps. You could also use date strings I believe.
Cloudant Query: https://console.bluemix.net/docs/services/Cloudant/api/cloudant_query.html
Cloudant Search: https://console.bluemix.net/docs/services/Cloudant/api/search.html#search