0

I am creating an Android app that will require user to input data everyday and I am using Firebase database to store those data, however on days that user did not input a data I want a new node to be created automatically in Firebase database so that I can use it to list and plot as I will need the date and a default value on those days. How can I create a node on Firebase database when date changes when there is no user input on that day?

Alex Mamo
  • 91,677
  • 13
  • 105
  • 138
kael
  • 3
  • 1

1 Answers1

0

You can achieve this in a very simple way, by adding default values to your properties. So assuming you have a database structure that looks like this:

Firebase-root
   |
   --- dateNode
          |
          --- propertyOne: null

You need to know that because there is no data that is assigned to the propertyOne field, the following refence will not even exist at all:

Firebase-root -> yourNode -> propertyOne //Will not appear in the database

If your property is of type String, then add a default value that looks like this:

Firebase-root
   |
   --- dateNode
          |
          --- propertyOne: ""

If you propertyOne is of type number, then add a default value that looks like this:

Firebase-root
   |
   --- dateNode
          |
          --- propertyOne: -1
Alex Mamo
  • 91,677
  • 13
  • 105
  • 138