Create new path in Firebase Realtime Database programmatically?

有些话、适合烂在心里 提交于 2020-01-06 09:05:31

问题


In Firebase documentation I don't found the anweser. How to add a new path in real-time database programmatically in Javascript? Like (just an example):

standard path: https://testapp.firebaseio.com/

And in the app I want to say something like: If this, then create a path like this: https://testapp.firebaseio.com/info/important/personal


回答1:


Keys and paths in the Firebase Database are automatically created when you write a value to them. So to generate the path info/important/personal, you would write a value under it. For example:

firebase.database().ref('info/important/personal').set(true);

This will generate the following JSON:

{
  "info": {
    "important": {
      "personal": true
    }
  }
}

Note that the inverse is also true: Firebase will automatically remove empty keys/paths. So if you delete the true above, the entire JSON will be deleted.



来源:https://stackoverflow.com/questions/51474305/create-new-path-in-firebase-realtime-database-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!