Firebase Firestore prevent client side creation of fields in a document
As per the above link, this has been asked before, but not correctly answered.
I can't seem to figure out how to prevent a user from uploading garbage data to random field names in a document. Although it's easy to enforce rules about existing fields in your 'schema', I haven't found anything that can stop the user from updating a document with
const payload = {
random123: 5,
anotherRandom123: 5
}
I understand that it might be possible to count the total number of fields and limit those, however, if a document happens not to have every field populated, you could still write garbage data. You could even check for certain field names with the in
operator and list functions. The only way I can imagine doing it is by forcing the document to always populate all the fields you might need, enforce a static number of fields and then check to ensure that every field name is present/correct.
This would not work if a document has optional fields.
Is this possible? What is the best way to solve this problem?