Select distinct of array of string


(James) #1

we have a predicate:

tags: [string] @index(term) .

how do we select distinct of all tags from all records?
it cannot be duplicate even thou 1st record may contains 2 tags that may contains in another record.
we want the record to return list of string with unique tags
and even, is it possible to sort them after getting the list?


(Michel Conrado (Support Engineer)) #2

I have a gist with similar examples see what you can get from it https://gist.github.com/MichelDiz/2e434fcd4a4536da20a63b127a04a600#file-schema-schema

in the example I explore more the use of Tags by String.

If you wanna unique tags use tags: uid @reverse . But with string you can do it too, but you have to do checks to make sure that all strings are unique. Like Upsert Procedure.

I believe tags by UID (nodes) are better because you can see the relation visually. And do “count” more directly.


(James) #3

hi @MichelDiz,

do you meant that i would have insert string of any value to be stored as uid?


(Michel Conrado (Support Engineer)) #4

I don’t get this statement. Strings/int/date/any are not converted to UIDs. What I meant is that your tags could be Nodes.