问题
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