How to Delete from Firebase Realtime Database

How to delete from firebase realtime database?

If you don't know the key of the items to remove, you will first need to query the database to determine those keys:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
Query applesQuery = ref.child("firebase-test").orderByChild("title").equalTo("Apple");

applesQuery.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot appleSnapshot: dataSnapshot.getChildren()) {

public void onCancelled(DatabaseError databaseError) {
Log.e(TAG, "onCancelled", databaseError.toException());

How can I delete some data from Firebase Realtime Database?

You need make a DELETE request at the location you need to delete.

curl -X DELETE \
const request = new Request('', { method: 'DELETE'})
const response = await fetch(request)
return await response.json()

I'm not sure about how your database structure looks like but the above request will delete the whole "locations" node. Here's an example:

Sample Image

If you want to delete only location2, then make a delete request at https://[PROJECT_ID]

I'm not sure if there's any specific reason for you to use the REST API but you can try using Firebase Web SDK. It's easier to use, for example to delete location2:


How do I delete a database from Firebase?


To delete ONLY the database just delete the top level object/node.

Click on your project (the white box below, hiding name):


Then click on gear (settings) icon and click "Project Settings":


Scroll to bottom and click "DELETE PROJECT":


How to delete a node in firebase realtime database in javascript

Your fourth example should work, except you have a typo:

let chatRef = db.ref("/chats/MJy8cxO85ldEnDScsWZ");

It should instead be:

let chatRef = db.ref("/chats/-MJy8cxO85ldEnDScsWZ");

You're missing the "-" before "M".

how to delete firebase realtime database child node with key?

It seems you are using Firebase Modular SDK (V9.0.0+) where both ref() and remove() are top-level functions. Try refactoring the code as shown below:

// import the functions
import { getDatabase, ref, remove } from "firebase/database";

confirmDelete(e) {
const db = getDatabase();

// create DatabaseReference
const dbRef = ref(db, "/ships/" +;

remove(dbRef).then(() => console.log("Deleted"))

Checkout the documentation to learn more about the new syntax.

How to delete many of data in Realtime Database

There is support for deleting large nodes built into the Firebase CLI these days as explained in this blog How to Perform Large Deletes in the Realtime Database:

If you want to delete a large node, the new recommended approach is to use the Firebase CLI (> v6.4.0). The CLI automatically detects a large node and performs a chunked delete efficiently.

$ firebase database:remove /path/to/delete

My initial write-up is below. I'm pretty sure the CLI mentioned above implements precisely this approach, so that's likely a faster way to accomplish this, but I'm still leaving this explanation as it may be useful as background.

Deleting data is a write operation, so it's by definition going to put load on the database. Deleting a lot of data causes a lot of load, either as a spike in a short period or (if you spread it out) as a lifted load for a longer period. Spreading the load out is the best way to minimize impact for your regular users.

The best way to delete a long, flat list of keys (as you seem to have) is to:

  1. Get a list of that keys, either from a backup of your database (which happens out of band), or by using the shallow parameter on the REST API.
  2. Delete the data in reasonable batches, where reasonable depends on the amount of data you store per key. If each key is just a few properties, you could start deleting 100 keys per batch, and check how that impacts the load to determine if you can ramp up to more keys per batch.

Delete a node from Firebase realtime database with android studio java Recycler view

According to your comment:

I can navigate until to the node that provided by firebase authentication (LP6RF0KD7Ve66snlayZjpSotQEJ2) using this: DatabaseReference db =FirebaseDatabase.getInstance().getReference("Prescription").child(authCode); db.removeValue() But this will delete the entire user's nodes

Indeed you are removing the entire node since your reference points exactly to that node. To be able to remove the -Ml-I9XVcNnOM8nc79sw node, you should create a reference that points exactly to that node:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference nodeToRemove = rootRef

Always remember that in order to remove a specific element, you need to create a reference that contains the name of all nodes, including the one that you want to delete.

If you don't have one of the keys, then you should store the value in a variable as explained in my answer from the following post:

  • How to get specific pushedID in Firebase?

Related Topics

Leave a reply