Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 通过使用unix时间戳,cloudant Db排序函数未按预期工作_Sorting_Pagination_Ibm Cloud_Cloudant_Node Red - Fatal编程技术网

Sorting 通过使用unix时间戳,cloudant Db排序函数未按预期工作

Sorting 通过使用unix时间戳,cloudant Db排序函数未按预期工作,sorting,pagination,ibm-cloud,cloudant,node-red,Sorting,Pagination,Ibm Cloud,Cloudant,Node Red,我正在使用“cloudant”数据库和node red应用程序。并使用节点红色应用程序存储所有数据。我使用random()字符串作为cloudant文档的“\u id”字段,一些文档包含系统生成的“\u id”字段,而一些文档是random()生成的字符串作为“\u id”。所有具有“createdAt”字段的记录,该字段存储我通过javscript date obejct获得的“Unix时间戳”,即“new date().getTime()” 我使用以下设计文档创建了CloudantDB排序索

我正在使用“cloudant”数据库和node red应用程序。并使用节点红色应用程序存储所有数据。我使用random()字符串作为cloudant文档的“\u id”字段,一些文档包含系统生成的“\u id”字段,而一些文档是random()生成的字符串作为“\u id”。所有具有“createdAt”字段的记录,该字段存储我通过javscript date obejct获得的“Unix时间戳”,即“new date().getTime()”

我使用以下设计文档创建了CloudantDB排序索引,即

{
    "ddoc": "_design/629170abb04bb25e13d65322e59141dcc5d16317",
    "name": "customIndex",
    "type": "json",
    "def": {
        "fields": [{
            "createdAt": "asc"
        }, {
            "page_id": "asc"
        }, {
            "task_id": "asc"
        }, {
            "_id": "asc"
        }]
    }
并使用以下查询获得结果,即

{
"selector": {
    "createdAt": {
        "$gt": 0
    },
    "$or": [{
        "task_id": {
            "$in": ["1_0"]
        }
    }, {
        "page_id": 1
    }],
    "table": "details"
},
"sort": [{
    "createdAt": "desc"
}],
"limit": 20 , "bookmark": null}
具有以下cloudantDb端点

我不知道我遗漏了什么,但是cloudantDB没有按它应该的方式对记录进行排序,有时会返回随机记录而不进行任何排序

我将按照以下链接实现带有排序索引的cloudantDb find查询,即

任何形式的帮助或建议都将不胜感激


提前谢谢

Cloudant记录是JSON文档,JSON规范不支持JavaScript日期类型。你不是唯一遇到这个问题的人。请看JasonSmith的回答

啊,对了
new Date().getTime()
实际上返回一个数字。我无法访问你的数据库,所以这对我来说很难测试。再看一遍之后,我认为您的问题可能是您手动创建了该设计文档,并试图对其运行Cloudant查询选择器。不幸的是,这行不通。要运行Cloudant查询选择器,还需要通过Cloudant查询创建索引。看见希望这就是问题所在?谢谢@brobes的建议。我已经为选择器查询创建了CloudantDb索引,CloudantDb在运行上述查询时没有返回任何警告或错误。如果我缺少索引,那么我认为CloudantDb肯定会返回一些警告或错误。好吧,如果是这样的话,也许您需要熟悉CouchDB视图排序规则?它们控制着索引的排序顺序,所以也许就这么简单?