In Firestore, do all document have to be identical in respect of their fields?
Example:
If document A has two fields, field 1 and field 2 and document B only has field 1, when I run a query related to field 2, then is there a way to put in a nullpointer check because I know that docment B would give me an error.
I know that documents are never null, but I was wondering if there was a way of putting in a safety measure on the field level?
Note: to Doug and Alex as my response is too long:
Thanks Alex and Doug, I remember viewing the video which indicated that Firestore is free-form and hence I constructed the database to be such i.e. allow me to expand as my app develops.
I understand your example query above with the whereEqualTo
of null
but if i had a query as follows:
`queryForNullvalues = rootref.collection("coll).whereEqualTo("Field1","some random value")`,
Then when I get down to the next level and I have a
val fieldvalue = value.getString("field2") ,
Then what you will find is that the app crashes because if I was doing this query on document 2, field 2 does not exist. This is inherently where the issue lies. Is the app meant to crash on that? because the logcat would give an error of nulpointer. Just to be clear if i were to use
val fiedlvalue = value.getString("field1")
It doesn't crash as field1 exists in both documents