Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an empty child record in Firebase

Tags:

firebase

I am trying to create a child using the Firebase data view but it seems that this is not possible as the create node directly disappears or rather doesn't show up at any time. I tried to leave the value field empty but this doesn't work at all as well as writing null into the value field. Am I doing it wrong?

-Fabian

like image 411
user1581535 Avatar asked Apr 09 '13 19:04

user1581535


People also ask

What is orderBy in Firebase?

By default, a query retrieves all documents that satisfy the query in ascending order by document ID. You can specify the sort order for your data using orderBy() , and you can limit the number of documents retrieved using limit() .

How do I know if my DataSnapshot is empty?

You can use hasChildren() to determine if a DataSnapshot has any children. If it does, you can enumerate them using forEach() . If it doesn't, then either this snapshot contains a primitive value (which can be retrieved with val() ) or it is empty (in which case, val() will return null ).

How do I manually add data to Firebase?

If you open your app from Firebase dashboard, you can add data manually by clicking on the + sign. We will create a simple data structure.


1 Answers

Null and empty values are the same as the record not existing. If you want it to exist, you have to set a value.

In other words, when you test for a record's existence, you aren't looking to see if the key is in the database, you are looking to see if the path (the location of that key) has any data.

Suggestion: use a falsy value like 0 or false until you have some data to throw into that location. You're not limited by data types as you would be with SQL, so you can always replace that with an object/array/et al later.

like image 95
Kato Avatar answered Oct 05 '22 06:10

Kato