I am manually adding data for an app I am creating. I have to add many documents to a collection, all of which have to contain the same 5 fields. Is there a way to automatically create these fields when I create a new document in the Firebase console? And to also enforce all documents have those 5 fields (so that I don't make mistakes) ?
Additionally, is there a better way to manually adding this data than from the Firebase console? Through JSON for example?
There are two separate questions here. Both have been answered before, but never in a single question, so I'll do that here.
This is not possible. You will have explicitly write those values into each new document you create.
This is possible through the use of Firebase's server-side security rules.
For example, to ensure a document has values for field1, field2 and field3, you could use hasAll:
allow write: if resource.data.keys().hasAll(['editor', 'admin']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With