Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
How to delete object from firebase database

I'm trying to figure out how to delete information submitted to the firebase database. I am trying to delete information under the requests. Example

Here are my actions used to fetch the data:

export default {
async contactArtist(context, payload) {
    const newRequest = {
        userEmail: payload.email,
        message: payload.message
    };
    const response = await fetch(`https://find-artist-d3495-default-rtdb.firebaseio.com/requests/${payload.artistId}.json`, {
        method: 'POST',
        body: JSON.stringify(newRequest)
    });

    const responseData = await response.json();

    if (!response.ok) {
        const error = new Error(responseData.message || 'Failed to send request.');
        throw error;
    }

    newRequest.id = responseData.name;
    newRequest.artistId = payload.artistId;

    context.commit('addRequest', newRequest);
},
async fetchRequests(context) {
    const artistId = context.rootGetters.userId;
    const token = context.rootGetters.token;
    const response = await fetch(`https://find-artist-d3495-default-rtdb.firebaseio.com/requests/${artistId}.json?auth=` + token);
    const responseData = await response.json();

    if (!response.ok) {
        const error = new Error(responseData.message || 'Failed to fetch requests.');
        throw error;
    }

    const requests = [];

    for (const key in responseData) {
        const request = {
            id: key,
            artistId: artistId,
            userEmail: responseData[key].userEmail,
            message: responseData[key].message
        };
        requests.push(request);
    }
    context.commit('setRequests', requests);
},

};

I'm trying to set up a button that will delete the selected request object.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your code is sending a POST request, which tells Firebase to generate a unique key. From the documentation on saving data:

POST: Add to a list of data in our Firebase database. Every time we send a POST request, the Firebase client generates a unique key, like fireblog/users/<unique-id>/<data>

The delete a node, send the DELETE verb/method to that path:

const response = await fetch(`https://find-artist-d3495-default-rtdb.firebaseio.com/requests/${payload.artistId}.json`, {
    method: 'DELETE'
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!