0
0
Firebasecloud~5 mins

Data validation rules in Firebase - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are Firebase data validation rules?
Firebase data validation rules are conditions set to check if data being written to the database is correct and safe before saving it.
Click to reveal answer
beginner
Why is data validation important in Firebase?
Data validation helps prevent bad or harmful data from entering the database, keeping the app reliable and secure.
Click to reveal answer
intermediate
How do you write a simple Firebase rule to allow only strings for a field called 'name'?
Use the rule: <br> "name": { ".validate": "newData.isString()" } <br> This checks that the new data for 'name' is a string.
Click to reveal answer
beginner
What does newData.exists() check in Firebase rules?
It checks if the new data being written actually exists (is not null or deleted).
Click to reveal answer
intermediate
How can you restrict a number field 'age' to be between 0 and 120 in Firebase rules?
Use: <br> "age": { ".validate": "newData.isNumber() && newData.val() >= 0 && newData.val() <= 120" }
Click to reveal answer
What does Firebase data validation rules do?
ADelete old data from the database
BAutomatically fix errors in data
CCheck data before saving to ensure it meets conditions
DEncrypt data in the database
Which function checks if new data is a string in Firebase rules?
AnewData.isBoolean()
BnewData.exists()
CnewData.isNumber()
DnewData.isString()
How do you ensure a field 'score' is a number greater than or equal to zero?
A".validate": "newData.isNumber() && newData.val() >= 0"
B".validate": "newData.isString() && newData.val() >= 0"
C".validate": "newData.exists()"
D".validate": "newData.isBoolean()"
What happens if data does not pass Firebase validation rules?
AThe data is saved anyway
BThe data write is rejected
CThe data is saved but marked invalid
DThe database crashes
Which of these is NOT a valid Firebase validation function?
AnewData.isDate()
BnewData.isString()
CnewData.isNumber()
DnewData.exists()
Explain how Firebase data validation rules help keep your database safe and reliable.
Think about what happens if wrong data is saved.
You got /3 concepts.
    Describe how to write a Firebase rule that only allows numbers between 1 and 100 for a field called 'rating'.
    Use logical AND to combine checks.
    You got /4 concepts.