Reputation: 83
I have a requiremnt in which I am getting stucked. Below are few points that needs to be done.
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.
Upvotes: 0
Views: 300
Reputation: 11
I ran into the same issue. In Javascript we see the same:
"2" > "13" -> true
"2" > 13 -> false
2 > "13" -> false
So comparing numerical string values will not work (because strings are not numbers). To compare numerical strings, a conversion must be done to numerical values.
Solution
You can set the key type to padded
in the key options for the collection ArangoDB collection creating.
For example via HTTP (I use Insomnia)
POST http://localhost:8529/_db/mydb/_api/collection
Basic Auth:
username: ...
password: ...
BODY (JSON encoded):
{
"name": "MyCollection",
"keyOptions": {
"type": "padded",
"allowUserKeys": false
}
}
Now the generated keys will look like this 00000000046f9984
. The 0
padding will make sure that the keys will sort correctly.
Upvotes: 1