29

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?

Bruno
  • 6,623
  • 5
  • 41
  • 47
  • Possible duplicate of [Firebase : Read-only & non-realtime mode activated to improve browser performance](http://stackoverflow.com/questions/38651204/firebase-read-only-non-realtime-mode-activated-to-improve-browser-performanc) – Jay Feb 12 '17 at 16:24
  • 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 Feb 12 '17 at 16:25
  • @Jay it is not duplicate because - # this has right title question for issue # this describe exactly fast simple solution. – Bruno Feb 12 '17 at 19:34

9 Answers9

68

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

Andrew Roberts
  • 2,720
  • 1
  • 14
  • 26
35

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 /
Charlouze
  • 461
  • 5
  • 4
  • 2
    This should be accepted as the correct answer IMO. Using curl / rest for this when there is the firebase CLI tool seems cumbersome and inefficient. – Thijs Koerselman Jul 13 '18 at 12:51
  • 1
    Project with multiple database instances can remove all data by specifying specific instance like so: `firebase --instance abcdef-r4566-45rty database:remove /` – Subrat Nov 06 '18 at 05:29
22

Why missing Firebase remove button ?

Alvin from Firebase Support :

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.


Remove all data from Firebase from command line

Firebase documentation show Removing Data - just they don't show how remove all data.

For remove all data you can use REST command - which remove whole JSON output on that node level

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

so you can do this on every generated "URL node in console" by adding JSON extension

https://{{project_id}}.firebaseio.com/{{path}}/{{path}}/{{path}}/.json
Bruno
  • 6,623
  • 5
  • 41
  • 47
  • 1
    @AlecRust it should work uri auth "https://{{name}}:{{password}}@{{project_id}}.firebaseio.com" – Bruno Sep 27 '17 at 14:40
5

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.

shifu
  • 672
  • 8
  • 37
tabebqena
  • 1,204
  • 1
  • 13
  • 23
5

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

nikhil sadalagi
  • 305
  • 3
  • 13
3

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);
}
MechMK1
  • 3,278
  • 7
  • 37
  • 55
Mateusz L.
  • 31
  • 3
1

Create a new JSON file with content as {}. Go to firebase console click on the 3 dots on right, click on import JSON, choose the newly created JSON file and it will delete all data from the firebase database.

IMRAN ABBAS
  • 119
  • 1
  • 2
0

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();
                        }
                    });
                }
            }

            .....
        });
Mahdi Safari
  • 298
  • 3
  • 12
-1

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();
}});
}}});
}