31

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?

3
  • Possible duplicate of Firebase : Read-only & non-realtime mode activated to improve browser performance Commented Feb 12, 2017 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. Commented Feb 12, 2017 at 16:25
  • @Jay it is not duplicate because - # this has right title question for issue # this describe exactly fast simple solution. Commented Feb 12, 2017 at 19:34

9 Answers 9

76

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. Worth an uptick?
super..:-) fastest way to clear the database..thanks
Haha. NIce. The Firebase guys forgot to keep a feature to manually delete database objects. Thanks!
If anyone is wondering, this works even for DB with high memory, for which the DELETE API fails stating too much data to be updated in one go.
36

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 / 

2 Comments

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.
Project with multiple database instances can remove all data by specifying specific instance like so: firebase --instance abcdef-r4566-45rty database:remove /
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 

1 Comment

@AlecRust it should work uri auth "https://{{name}}:{{password}}@{{project_id}}.firebaseio.com"
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.

2 Comments

FYI, Solution 1 (delete from the Forge), only works if you have a small enough database so that it can show the real-time view.
CLI did the job very well
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

Comments

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

Comments

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.

Comments

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

Comments

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

2 Comments

Please format your code and create a minimal example with enough relevant context added so a normal programmer could understand what you did and how it solved the problem
حكيني عربي طارق مافهمت قصدك،هادا كود كامل

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.