28
votes

I started using a code that using Firebase realtime database. I implemented it to my solution. Connection and control was perfect, so I used it for the production environment.

After a while I was doing upgrade and I need remove all data again - but wait, there are no delete buttons in console anymore at highest root level and only allowed in one selected item at once:

https://console.firebase.google.com/project/{{project_name}}/database/data

In last update shown only this message and no steps what next:

Read-only & non-realtime mode activated to improve browser performance Select a key with fewer records to edit or view in realtime

Q how can I remove all data at once?

8
I marked this as a duplicate as the question is very similar to another question, just phrased differently. The other part of the answer, is that it would take literally one line of code ( Swift: rootRef.setValue(nil) ) to delete the database, assuming you authenticate as an admin.Jay
@Jay it is not duplicate because - # this has right title question for issue # this describe exactly fast simple solution.BG BRUNO

8 Answers

49
votes

You can manually create a JSON file that contains a single empty entry and import it, which will remove all existing entries.

29
votes

A simple way to remove all data from a firebase database is to use the Firebase CLI.

Once the CLI is setted up you just need to use this command and your data will be removed :

firebase database:remove /
20
votes

I think there missing some hint - why missing delete button on root level or how can we do it and quickly anyway.

Alvin at Firebase Support was very helpful:

Record or node has too much data, which makes the data viewer switch to a read-only/non real time mode to increase the browser's performance.

Solution is very simply, just use REST. By their documentation Removing Data but they don't show how can I remove all.

For remove all data you can use by Alvin this:

curl -X DELETE "https://{{project_id}}.firebaseio.com/.json"

and it means you can do this with every generated URL node in console only by adding JSON extension:

https://{{project_id}}.firebaseio.com/{{path}}/{{path}}/{{path}}/.json

I hope this helps someone.

4
votes

Solution 1: console From your project, click on the x button at the top level of the database.

enter image description here

then click delete

enter image description here

Solution 2: Programmatic

whatever the language you are using , call something like:

database.set('/', null)

Solution 3: Firebase CLI from your project folder (you already installed the firebase-tools) write the following in the terminal then hit Enter :

database:remove /    

firebase CLI remove all data

N.B:

Kindly consider to backup your data first.

4
votes

I used

curl -X DELETE "https://<prject name>.firebaseio.com/.json?auth=<Firebase Database secret>"

This deletes the database also with the data which is blocked from firebase UI. Hope this helps. Thank you

FYI :

Your get Web API key is in https://console.firebase.google.com/project/<database name>/settings/serviceaccounts/databasesecrets

else you can go to Project overview settings >> project settings >> Service Accounts >> Database Secrets

Also I am wanted to comment it on the comments section but due to lack of stackoverflow point I am writing it as answer

2
votes

Programmatically you can implement a method, that puts an empty set of data on the main root of database - specifically you can insert a null.

In my Android project it looks like this:

void removeDataFromDatabase(){
    DatabaseReference root = FirebaseDatabase.getInstance().getReference();
    root.setValue(null);
}
0
votes

This code helps to remove one by one of your object in firebase realtime database. by path name object removes all children.

FirebaseDatabase.getInstance().getReference("yourReferance").addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
                for(DataSnapshot data : dataSnapshot.getChildren()) {
                    data.getRef().removeValue().addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {
                            Toast.makeText(getContext(), "Successfully remove", Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }

            .....
        });
-1
votes

sloved :

public void removeDataFromFirebaseDatabae(){
FirebaseDatabase.getInstance().getRefrence().child("what you will remove").addChildEventListener(new onChildListener(){
@override
public void onChildAdded(DataSnapshot dp,String str){
for(DataSnapshot dx : dp.getChildren()){
dx.getRef().removeValue().addOnSuccessListener(new onSuccessListener<Void>(){
@override
public void onSuccess(Void pvoid){
Toast.makeText(this,"remove success",5000).show();
}});
}}});
}