1

I am sending requests to the the Firebase Realtime API. When I try to delete an from item within from a specific collection (e.g. journals) and specify which journal title using axios.delete("https://topxxx-xxx.firebaseio.com/journals.json", {title: "Nature"}}) all of the journals in the collection are deleted, not just "Nature". Similarly, if I do a get request and specify a title, all journals are returned.

I have also tried using "https://topxxx-xxx.firebaseio.com/journals.json", {params: {title: "Nature"}}. but that also returns all journals. Here are an example delete request:

    axios.delete("https://topxxx-xxx.firebaseio.com/journals.json", {title: this.state.title})
      .catch(error=> console.log("Error" + error))
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
dougfair
  • 348
  • 1
  • 3
  • 12

3 Answers3

2

The Firebase Realtime Database API doesn't support conditional deletes. To delete a node, you must specify the entire part to that node, and (in the REST API) either use the DELETE verb or use the X-HTTP-Method-Override: DELETE header.

So the two step process:

  1. Perform a query to find the nodes with the title you're looking for:

    https://topxxx-xxx.firebaseio.com/journals.json?orderBy="title"&equalTo="the title"
    
  2. Delete the matching nodes by sending a DELETE to URLs like:

    https://topxxx-xxx.firebaseio.com/journals/journalId1.json
    
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
1

You cannot delete a specify item from a json file like that in firebase, and also using GET will return the entire collection. It is working amazingly correct from firebase side. If you want something like how you are expecting, go for a small flask server or checkout cloud functions in firebase

ajaidanial
  • 5
  • 1
  • 1
0

You probably want to send that request to a back-end services that's connected to firebase (i'm assuming since you're using axios). Then call the remove method as demonstrated here

A.B.
  • 31
  • 2
  • Thanks for your answer but I have seen numerous other reponse showing how to use axios.delete rather than remove (e.g. https://stackoverflow.com/questions/52694011/how-to-delete-a-single-item-using-axios-in-react). Perhaps I'm missing something important here.... – dougfair Sep 17 '19 at 04:46