In earlier post we learned how to write/set , update, push data into firebase. We are gonna see how to delete data from database
To remove data we are just gonna use remove function.
firebase.database().ref().child(‘path’).remove();
To remove a data we need to mention the accurate path of the node for example if we are gonna remove just user name. we need to set the path as “users/user_name”, for email the path will be “users/user_email”. if we gonna remove the users totally we will be using “users/” as the path. Lets see how to remove
Let’s create a page to remove all users data under a new node.
<!DOCTYPE html>
<html>
<head>
<meta name=”format-detection” content=”telephone=no”>
<meta name=”msapplication-tap-highlight” content=”no”>
<meta name=”viewport” content=”user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width”>
<title>Sample</title>
</head>
<body></body>
</html>
Add this to your script src tag “https://www.gstatic.com/firebasejs/4.3.1/firebase.js”
Create a script and add the below credentials
// Use your config instead of this one
var config = {
apiKey: “AIzaSyCuXlfTMDrC3rXdPb442CkMEwNhYqYHu-U”,
authDomain: “sample-c7c91.firebaseapp.com”,
databaseURL: “https://sample-c7c91.firebaseio.com”,
projectId: “sample-c7c91”,
storageBucket: “sample-c7c91.appspot.com”,
messagingSenderId: “219135436098”
};
firebase.initializeApp(config);
Now let’s remove data from firebase
Lets create a button to remove users.. lets push this data in to your firebase app.
<button onclick=”removeData()”>Push to Firebase</button>
Now let’s write a script to remove users from your firebase.
const fb_db = firebase.database().ref()
function removeData(){
fb_db.child(‘users/’).remove()
}
By following the above steps, you will be able to remove the data successfully from firebase.
After integrating the script and html, the code should look like this.

Note: Make sure you have replaced the firebase config with your Firebase project config.
Okay, In next post lets see how to Read data in firebase






