Reputation: 443
I am using Firebase realtime database in Python, and have structure data like this:
{
"users" : {
"-LuOXedSsg_1vZ9WBePA" : {
"name" : "Adam",
"password" : "adam",
"username" : "adam"
},
"-LuOXk-fE99ucZbrlBk_" : {
"name" : "Joi",
"password" : "joi",
"username" : "joi"
}
}
}
I want to delete the child("-LuOXk-fE99ucZbrlBk_") with this code:
# input
username_to_delete = input ("username:")
data = ref.get()
for key,val in data.items():
if (username_to_delete == val['username']):
delete_user_ref = ref.child(key)
delete_user_ref.set(None)
else:
print(usernameDoesNotExist)
I want to delete the child by setting it as NULL (None in Python), but when it starts and input the correct username, I get an error like this:
in set
raise ValueError ('Value must not be None.')
ValueError: Value must not be None.
what should i do? i am still new in firebase and python.
Upvotes: 4
Views: 6848
Reputation: 80944
You can use the delete()
method:
delete_user_ref.delete()
For reference check the following docs:
https://firebase.google.com/docs/reference/admin/python/firebase_admin.db
set(value) Sets the data at this location to the given value.
The value must be JSON-serializable and not None.
Parameters:
value – JSON-serializable value to be set at this location.Raises:
ValueError – If the provided value is None. TypeError – If the value is not JSON-serializable. FirebaseError – If an error occurs while communicating with the remote database server.
Upvotes: 4