按关键字和筛选器排序(_K)



我有一个被卡住的要求。以下是需要做的几点。

1: I want to sort on _key field which is system generated (configured as auto increment) and filter them accordingly. Eg: 
SORT users._key DESC
FILTER TO_NUMBER(users._key) > 1999968
The problem here is _key is string and I have to convert _key TO_NUMBER which doesn't seems to be a good approach, is there are way to correct it.
FILTER users._key > '1999968' is not giving correct results.
2: How to use grouping with views I need to group few records but it shows be error everytime I place COLLECT keyword.
eg: 
for suser in sortedUsers <----- view
SEARCH suser ._to == user._id <------ some searching (not actual code)
SORT suser ._key DESC <----------- sorting
FILTER suser ._key > 1999968 <-------- filtering
COLLECT temp = suser.country <---------- this is sample command not actual
return temp
But my question is where does the collect command goes when we use views.Even DINSTINCT  will work but how to sync it with complex queries that return complex results.

我遇到了同样的问题。在Javascript中,我们看到了相同的内容:

"2" > "13" -> true
"2" >  13  -> false
2  > "13" -> false

因此,比较字符串数值将不起作用(因为字符串不是数字(。若要比较数字字符串,必须将其转换为数值。

解决方案
您可以在创建集合ArangoDB的密钥选项中将密钥类型设置为padded

例如通过HTTP(我使用失眠(

POST http://localhost:8529/_db/mydb/_api/collection
Basic Auth:
username: ...
password: ...
BODY (JSON encoded):
{
"name": "MyCollection",
"keyOptions": {
"type": "padded",
"allowUserKeys": false
}
}

现在生成的密钥将类似于00000000046f99840填充将确保密钥正确排序。

最新更新