Reputation: 11
I am using "cloudant" database with node-red application. And stores all data via using node-red application. I am using random() string for cloudant document "_id" field, some of document contains system generated "_id" field whereas some document are random() generated string as "_id". All the records having the "createdAt" field which stores "Unix Timestamp" which I am getting through the javscript date obejct i.e "new Date().getTime()".
I created the CloudantDB sort index via using the following design document i.e
{
"ddoc": "_design/629170abb04bb25e13d65322e59141dcc5d16317",
"name": "customIndex",
"type": "json",
"def": {
"fields": [{
"createdAt": "asc"
}, {
"page_id": "asc"
}, {
"task_id": "asc"
}, {
"_id": "asc"
}]
}
and using the following query to get the result i.e
{
"selector": {
"createdAt": {
"$gt": 0
},
"$or": [{
"task_id": {
"$in": ["1_0"]
}
}, {
"page_id": 1
}],
"table": "details"
},
"sort": [{
"createdAt": "desc"
}],
"limit": 20 , "bookmark": null}
with following cloudantDb endpoint
https://30175cba-a69e-4ff0-9a79-788abcf0f585-bluemix.cloudant.com/master_table/_find
I don't what I am missing but cloudantDB doesn't sort the records as it should be and sometime return random records without any sorting
I am following the following link to implement the cloudantDb find query with sort index i.e
https://developer.ibm.com/clouddataservices/cloudant-query-new/
any kind of help or suggestion is appreciated.
Thanks in advance.
Upvotes: 0
Views: 737
Reputation: 716
Cloudant records are JSON documents, and the JSON spec does not support JavaScript date types. You're not the only person to hit this problem. See this answer from JasonSmith https://stackoverflow.com/a/4815878/1459475
Upvotes: 1