Currently I can't seem to find a way to delete an object from firebase list via REST api. For example I am trying to remove this from the list: https://mrdapper.firebaseio.com/v0/users/41/favs.json?orderBy=%22id%22&equalTo=107657061
Posting a DELETE request doesn't work with query parameter.
You can't delete with a query, (although that would be awesome). But you can use the results to send a DELETE request.
Do a GET:
GET https://mrdapper.firebaseio.com/v0/users/41/favs.json?orderBy=%22id%22&equalTo=107657061
This will return the object and you can send a DELETE request for each item it returns.
DELETE https://mrdapper.firebaseio.com/v0/users/41/favs/<returned-id>.json
Now, you may not like sending one delete request per object. But, with your data structure this is necessary.
If you'd like to easily query and delete items, you could try this data structure:
/users/$user_id
/userFavs/$user_id/$fav_id
Store the favs
in it's own location under the root. This will allow you to retrieve user
data without always getting the favs
.
For userFavs
if you key off userid
and the favid
you can easily query and delete.
{
"userFavs": {
"41": {
"107657061": {
"note_count": 43633
}
}
}
}
Now you can easily get all of the the user's favorites by specifying the user's id. If you need to delete by an id, that is also a key. So you can now DELETE without querying.
DELETE https://mrdapper.firebaseio.com/v0/userFavs/41/107657061.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With