Firebase set data structure

寵の児 提交于 2020-01-24 12:11:50

问题


Hi I'd like to know if there's a way to force the DB structure when using Firebase Console.

For example I need to add an object with name: "Sample" and value: 3, then when I want to add another object i can only insert object with the same structure (name and value). Is there any way to achieve this?


回答1:


There is no way to enforce a certain data structure when entering data using the Firebase Console.

When you access the Firebase Database through the Firebase Console (console.firebase.google.com), you are accessing the database as an administrative account. Such administrative access bypasses the security rules: all reads and writes are allowed and data is not validated.




回答2:


After you have completed the registration in Firebase, you can follow this example to put data in your Firebase Console:

DatabaseReference ref = FIRDatabase.database().reference()

String user_key = ref.childByAutoId().key
ref.child("Users").child(user_key).setValue(["username": username, number: "3"])

It is very simple!



来源:https://stackoverflow.com/questions/39440491/firebase-set-data-structure

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