When I tried to store an array like test: []string{"hello", "bye"}
using dgo
and queried for test
, I only get back "hello"
. Seems like the closest way to store an array in Dgraph is to create multiple objects and point them towards a single node. If that is the case, how would you store a list of fixed length? or ensure the number of list nodes does not exceed the intended list size (e.g. having a todo list with only 10 slots)?
Asked
Active
Viewed 628 times
1

sdfsdf
- 5,052
- 9
- 42
- 75
1 Answers
0
You can create and get an array of string as follows
**Query to create array of strings**
{"set":[{
"StringArray" : ["Hi", "hello"]
}]}
**Query to fetch array of strings**
{q(func:has(StringArray)){
uid
StringArray
}}
In dgraph it is called as List Type Ref: https://docs.dgraph.io/query-language/#list-type

Suyog
- 1
- 2
-
"A set operation adds to the list of values. The order of the stored values is non-deterministic." Is there a way to store arrays of primitive types that retain their order? I'm thinking you stringify an array and store it as a string. – sdfsdf Jan 19 '20 at 22:20
-
@sdfsdf It's not currently possible to save values as a true list, your proposal to stringify the array is the only way. – Jan 26 '21 at 22:42