Recently, I delved into learning more about Firebase and decided to create a basic database.
After following all the steps on the website, I successfully added members to the database.
Now, my next challenge is figuring out how to remove a user from the database.
Below is the code snippet for adding and removing users:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="saveData()">Save Data</button>
<button onclick="printData()">Print Data</button>
<button onclick="printData2()">Print Data2</button>
<button onclick="remove()">Remove</button>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script>
var ref = new Firebase("https://projecttest-9aee9.firebaseio.com/web/saving-data/fireblog");
var usersRef = ref.child("users");
function saveData(){
usersRef.set({
alanisawesome: {
date_of_birth: "June 23, 1912",
full_name: "Alan Turing"
},
gracehop: {
date_of_birth: "December 9, 1906",
full_name: "Grace Hopper"
}
});
}
function printData(){
usersRef.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
}
function printData2(){
ref.child("users/gracehop/date_of_birth").on("value", function(snapshot) {
console.log(snapshot.val());//"December 9, 1906"
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
}
function remove(){
ref.removeUser({
alanisawesome: {
date_of_birth: "June 23, 1912",
full_name: "Grace Hopper"
}
});
}
</script>
</body>
</html>
Any insights on what's causing issues with the remove users function?
Your help is greatly appreciated!