Hi, I am working with a fairly generic object/document type that has a map of KV pairs, where the value is an array of variants, and the type is specified in the variant itself. So, a single entry in the object/document could look something like this:
The first item in the array is the name of the data type, followed by the value. A single document is a list of these types of entries.
Is this something that can be modeled in dgraph?
I’ve been trying a number of different permutations for the Schema, with no luck. Is this possible with custom types? Any materials or example(s) for something like this?
Thanks for the reply. I think facets will work for this. Will that solution maintain the order? And will it support multiple values of the same type in the same list (appears so)? TBH, the types are not so important to save here if dgraph supports having strings and integers in the same list like your example. (it is just how the source system renders them)
Would it work (and maintain order) simply as this?
{
"key": "My Key",
"value": [
"my label string",
"701.92 USD",
8989832
]
}
Also to be aware of with lists, is that they work as a set. If you have two identical values in key value pairs and didn’t care about order, it might still produce the wrong results as
Hi, I’ve restructured my data quite a bit so that I believe it should be able to support both order and labels for content. However, I now receive the following error:
Lists (in this case Value List type) in Dgraph are similar to “sets” in JS. But it can’t hold arrays, objects and so on. Just the value as a list. And each value is unique.
Even for an edge, you can’t add it as arrays as you do in a JS Object for example. So your mutation should look like this:
It can’t be like { "content_groups": [ [ { .. } ], [ { .. }, { .. } ] ] }
have to be like { "content_groups": [ "edge": [ { .. } ], "edge": [ { .. }, { .. } ] ] }
Which in graph pattern means
content_groups => edge => Objects