I would like to be able to store an array of whatever type (as a scalar) to a node. An example would be that I have an array of 3 datetimes and would like to be able to store them all to a similar edge "graduation_dates". I would like to be able to search if ANY graduation date is <= Today + 1 week and > Now. If any of them match that, I would like it to return the item (whatever properties I am querying for). I would also like to be able to update that list. Appending to it, or removing from it (based on the value of the item I am storing). So, If I had a string array ("nicknames"), I would like to be able to delete a specific nickname (maybe like delete
So in summary, it would be nice to store an array (of whatever scalar type) and be able to perform full filtering on all of it's values as well as mutate specific items of the list or the list all together as well. If this functionality exists, I am unaware of it.
Exactly about to post the same feature idea / request.
Quick example:
mutation {
set {
_:0 <first_name> "Jack" .
_:0 <has_occupation> "dog breeder" .
_:0 <has_occupation> "ceo" .
_:0 <has_occupation> "philanthropist" .
}
}
When querying:
{
"me": [
{
"_uid_": "0x1e0",
"first_name": "Jack",
"has_occupation": "philanthropist"
}
]
}
But it would be great to include a feature where we can add these instead of replacing them (here, it should return philanthropist, ceo, dog breeder, for example.)
Especially with Knowledge Graphs, often the same predicate applies several times with different values for the same node. And one should not replace the other but instead add to it.
We need to start supporting a list of values. @pawanrawal is looking into it.
This should be easy given how we store our data internally in posting lists. The schema can be used to mention when a predicate should store a list of values ([string], [int]) and when a single value (present case).
@willcj33 @lazharichir Is the ordering of the items important when you want the whole list back? Even if we keep the order, a delete followed by a set would put the value at the end of the list.
The way I am thinking of implementing this is
has_occupation: [string] @index(term) .
S P * deletion to clear the list. You can do sets after doing S P * to replace the list.Thanks @pawanrawal - but is this also ok with UID predicates and not int/string as this is how I'll use them the most: <term> <defines> <topic_uid> (weight=...) or could be <person> <has_occupation> <occupation_uid> (from=DATE,to=DATE)
The order is not very important as generally with query the whole list back sorting by the predicate's value (weight, generally.)
@pawanrawal
@count could be used as well? As long as each item in the array respects the typical scalar filtering, I'm good with that.@lazharichir We already support this for UID predicates. In fact, that is how you would add friends to a person. E.g. (https://tour.dgraph.io/intro/3/). Did you mean something else? And as you mentioned, you can sort those by a facet weight or some other predicate.
@willcj33 Thanks for the feedback. Yes count(occupations) should work well. I will get started on this.
Update (21-08-2017)
We are not supporting paging the list for now.
This feature is in master as of 1728afa703813e66ff620c5cc4bd4a5783e843bd.
Most helpful comment
Exactly about to post the same feature idea / request.
Quick example:
When querying:
But it would be great to include a feature where we can add these instead of replacing them (here, it should return philanthropist, ceo, dog breeder, for example.)
Especially with Knowledge Graphs, often the same predicate applies several times with different values for the same node. And one should not replace the other but instead add to it.