Slice of slices, list of lists, array of arrays

Hey,

it it possible to store something like [][]string in a predicate?

If so, will it keep the order? will it be indexes?

thanks

There’s no default type in Dgraph that would let you do this easily. There are some options.

You could convert your [][]string into JSON and then store it in the predicate as a string. This is cumbersome however and you won’t be able to index the predicates unless you write a custom indexer yourself. Personally, I wouldn’t recommend it.

You could also do it by having to predicates. From a node you have one predicate (let’s call it pred1) that points to another node. This node has another predicate (let’s call it pred2) that points to a list of strings. You get indexing but you cannot keep the ordering.

So it would look a bit like this:

node1 -- pred1 --> node2 -- pred2 --> list of strings
node1 -- pred1 ---> node3 --- pred2 --> another list

However, I would suggest to try to see if there’s a simpler way to represent your data. Keeping the types simple will help you keep your queries and mutations simple as well. I don’t have a lot of context on what you are trying to do so I am not sure if this is possible.

2 Likes