swift - query.ref.removeValue removes the entire child instead of just a node -


i attempting remove 1 specific node database querying , calling query.ref.removevalue() though every time piece of code runs deletes entire child instead of node. code looks this...

let query = (ref?.child("groups").child("martins").child("messages").queryequaltovalue(selectedvalue))  query!.ref.removevalue() 

my database looking this...

it starts child named "groups" name of group child named "messages" , inside want able individuall delete nodes instead of deleting whole messages child.

thanks help, appreciate it.

the query reference points location query defined on, not elements matches. query!.ref.removevalue() remove entire location.

to remove individual items query matches, you'll need attach listener query , iterate on children:

let query = ref?.child("groups").child("martins").child("messages")                 .queryorderedbykey("item").queryequaltovalue(selectedvalue)  query.observeeventtype(.childadded, withblock: { (snapshot) -> void in   snapshot.ref.removevalue() }) 

Comments