Updating individual parent and child nodes within Firebase through use of a C# application.
A question that is often asked evolves around in one of the previous posts where we are taken through how to delete data within the Firebase database. In the post we go through how to delete all data within the database. This can be a useful feature if you want to carry out an entire wipe and clear out everything. But in the real world it wouldn’t make much sense. And so in this post we are covering the deletion of only specific parent and child nodes.
When starting off this project our objective was to find a way to remove only specific parent and/or child nodes and leave data that we are still in need of. In this example our database is already filled with example data. A sample of what is being stored currently within the database can be seen below.
{
"Users": [
"",
{
"1": "",
"Name": "John",
"Surname": "Smith",
"Title": "Mr"
},
{
"2": "",
"Name": "Jane",
"Surname": "Doe",
"Title": "Mrs"
},
{
"3": "",
"Name": "Hugo",
"Surname": "Strange",
"Title": "Dr"
},
{
"4": "",
"Name": "George",
"Surname": "Lucas",
"Title": "Mr"
}
]
}
Looking at the above we can see four entries under Users, each of these entries having their unique identifier, name, surname and title fields. This post will go through how we can remove for example the last entry from the above Mr George Lucas.
https://PROJECT_NAME.firebaseio.com/.json
The URL above points to the entire project and so carrying out a delete would wipe everything, instead we are required to narrow down within the JSON tree to a particular parent or child node for example the below would point to Mr George Lucas. Carrying out the delete here would remove this final entry and leave the others.
https://PROJECT_NAME.firebaseio.com/Users/4/.json
The above would then delete all contents of parent named 4 which in this case is the unique identifier for Mr George Lucas and holds all of his information. You could take this example a step further and delete only his surname. An example of how this would look can be seen in the below.
https://PROJECT_NAME.firebaseio.com/Users/4/Surname/.json
In the same way you could also update the the child of a specific parent node and this would work in a similar way.