I’ve gone thru every google search and example I can find, but I must be doing something wrong. I am unable to actually delete linked nodes.
Dgraph version : v1.2.2
Dgraph SHA-256 : 86e27921d3a53dbc4faba78e9c7d7879ce8bafd6006c9fd4b77220535b8ae1c2
Commit SHA-1 : 21cc8936
Commit timestamp : 2020-03-19 12:13:11 -0700
Branch : HEAD
Go version : go1.13.5
Schema example
type Person {
person_name
person_hasPet
}
person_name: string @index(term, fulltext) .
person_hasPet:[uid] @count @reverse .
type Pet {
pet_name
pet_isAnimal
}
pet_name: string @index(term, fulltext) .
pet_isAnimal:[uid] @count @reverse .
type Animal {
animal_name
}
animal_name:string @index(term,fulltext) .
Sample Data
{
"set": [{
"uid": "_:animal3",
"dgraph.type": "Animal",
"animal_name": "reptile"
},
{
"uid": "_:animal4",
"dgraph.type": "Animal",
"animal_name": "avian"
},
{
"dgraph.type": "Person",
"person_name": "Pablo",
"person_hasPet": [{
"dgraph.type": "Pet",
"pet_name": "Spot",
"pet_isAnimal": {
"uid": "_:animal3"
}
},
{
"dgraph.type": "Pet",
"pet_name": "Polly",
"pet_isAnimal": {
"uid": "_:animal4"
}
}
]
}
]
}
Verify the data set looks good
{
q(func: type(Person)) {
uid
expand(_all_) {
uid
expand(_all_) {
uid
expand(_all_)
}
}
}
}
Query returns something like this
{
"data": {
"q": [
{
"uid": "0x4e4c",
"person_name": "Pablo",
"person_hasPet": [
{
"uid": "0x4e4d",
"pet_name": "Spot",
"pet_isAnimal": [
{
"uid": "0x4e4f",
"animal_name": "reptile"
}
]
},
{
"uid": "0x4e4e",
"pet_name": "Polly",
"pet_isAnimal": [
{
"uid": "0x4e4b",
"animal_name": "avian"
}
]
}
]
}
]
}
}
Use case: Pablo had two pets, but one died, so I want to remove the pet “Spot” from Pablo.
I want to keep his second pet as is. And I don’t want to delete the Animal node “reptile” from dgraph as other Animals will have the same uid link.
Nothing seems to work correctly I’m always left with 0x4e4d hanging there which makes my query ‘count(person_hasPet)’ incorrect.
Various mutations I’ve tried (which all return “Success” not matter what).
{
"delete": {
"dgraph.type": "Pet",
"uid": "0x4e4d",
"pet_isAnimal": {
"uid": "0x4e4f"
}
}
}
{
"delete": {
"dgraph.type": "Pet",
"uid": "0x4e4d"
}
}
{
"delete": {
"dgraph.type": "Pet",
"uid": "0x4e4d",
"pet_isAnimal": null
}
}
{
"delete": [{
"uid": "0x4e4e",
"dgraph.type": "Pet",
"pet_name": "Polly",
"pet_isAnimal": {
"dgraph.type": "Animal",
"uid": "0x4e4b"
}
},
{
"dgraph.type": "Animal",
"uid": "0x4e4b"
}
]
}
Can anyone point out my mistake(s)?