Search code examples
jsonfirebasefirebase-realtime-databasexmlhttprequesthttp-delete

firebase delete xmlhttp request with equalTo


  DellContact=(emailcontact) => { 
            let {xhttp}=this.DbConn('DELETE','.json?orderBy="email"&equalTo="' + emailcontact + '"');
            xhttp.send();
    }
    
     DbConn (method, addon){
            let xhttp = new XMLHttpRequest();
            let url = "https://phonebook-496ff-default-rtdb.firebaseio.com/Contacts" + addon;
            xhttp.open(method,url,true);
            xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
            return {xhttp};
        } 

hello, im trying to delete the specific data from firebase by comparing the JSON value named "email" with the value emailcontact. i get a bad request 400. its something with the request syntax i think, because with GET/POST it works. firebaseURL/Contact.json?orderBy="email"&equalTo="[email protected]" <-- This is the request that sent Any suggestions ?


Solution

  • Firebase Realtime Database doesn't support update or delete queries. To delete a node, you need to know its exact path.

    So you'll need to:

    1. Execute a GET for the query to determine the results.
    2. Then loop over the results in your application code.
    3. Execute a DELETE request for each individual result.