What’s the best way to pop and push to array of strings/uids of unknown size, could be large
Note that the types in Dgraph such as [string]
are not arrays, but sets. If you want array mechanics (ordering, duplicates) you can store a json array string and manually read, deserialize, perform your operation, serialize, and write.
The semantics of sets are followed by the [string]
and all the [x]
types. So duplicates will be swallowed and order will not guaranteed, if you choose to use them.
Noted. But is there a way to add/delete items from these sets or are they immutable and can only be replaced?
When you write a new set it adds to the existing set by default. To remove a single one from a set you use the S-P-O delete method. To remove the whole set use the S-P-* logic
Why not use a list of nodes? A Graph DB is a very versatile type of DB. You can manipulate it in several ways(just need to be creative and learn DQL very well) for example this How to store ordered data? - #4 by MichelDiz - what I was explaining there is a kind of “linked list type”. Very common in several languages and algorithms.
The list type is a simple set/compound of scalar(int, string and so on). You can’t have duplicates in there. But with edges you can have the array logic.