简体   繁体   English

无需用户输入即可在几天内执行基于Firebase的数据库

[英]Firebasedatabase on days with no user input

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. 我正在创建一个Android应用程序,该应用程序将要求用户每天输入数据,并且我正在使用Firebase数据库存储这些数据,但是在用户没有输入数据的日子里,我希望在Firebase数据库中自动创建一个新节点。可以使用它来列出和绘图,因为我需要这些日期的日期和默认值。 How can I create a node on Firebase database when date changes when there is no user input on that day? 当日期更改且当天无用户输入时,如何在Firebase数据库上创建节点?

You can achieve this in a very simple way, by adding default values to your properties. 您可以通过向属性添加default值,以非常简单的方式实现此目的。 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: 您需要知道,因为没有数据分配给propertyOne字段,因此以下引用将根本不存在:

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: 如果您的属性的类型为String,则添加一个类似于以下内容的默认值:

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

If you propertyOne is of type number, then add a default value that looks like this: 如果您的propertyOne是数字类型,则添加一个默认值,如下所示:

Firebase-root
   |
   --- dateNode
          |
          --- propertyOne: -1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM