ddibiase
(David Di Biase)
May 27, 2018, 11:08pm
1
I have a predicate list with the schema format of:
Token: [string] @index(exact) .
I’d like to either remove a single element from the array OR override the whole array. The former is preferred over the latter. I can’t seem to find documentation on this. The relevant section states:
A delete operation deletes the value from the list.
in the section https://docs.dgraph.io/query-language/#list-type
MichelDiz
(Michel Diz)
May 28, 2018, 4:26am
2
Hi David Di Biase,
Sure you can do it, I’ll show you.
Let’s create our List:
{
set{
_:MyList <testList> "Banana" .
_:MyList <testList> "Apple" .
_:MyList <testList> "watermelon" .
_:MyList <testList> "Strawberry" .
_:MyList <testList> "Grape" .
}
}
Now We search for that Node to get its UID:
{
MyList(func: has(testList)) {
uid
expand(_all_)
}
}
The result will be:
{
"data": {
"MyList": [
{
"uid": "0x2711",
"testList": [
"Grape",
"Strawberry",
"Banana",
"Apple",
"watermelon"
]
}
]
}
Now we wanna delete just one fruit (Apple) from our list (It’s case sensitive):
{
delete {
<0x2711> <testList> "Apple" .
}
}
The result will be:
{
"data": {
"MyList": [
{
"uid": "0x2711",
"testList": [
"Grape",
"Strawberry",
"Banana",
"watermelon"
]
}
]
}
That’s all,
Any doubt I am available.
Cheers.
1 Like
system
(system)
Closed
June 27, 2018, 4:26am
3
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.