Suppose a Person has a list of Tools - I just learned that an empty collection is not the same as a NULL value, so there are two ways in which person.tools could be empty.
My first thought was, set a default value of [] for the Person.tools property, but there's no such thing as default values for properties (?)
My issue is, when dealing with document objects, you constantly need guard clauses around code that uses these collections, e.g.
if (person.tools) {
person.tools.forEach(...);
}
In a sense, it feels like the property-type isn't strictly List<Tool> but something more like Nullable<List<Tool>> which isn't really what I wanted...
Setting "Mandatory" and "Not Null" doesn't really solve the problem either, because it doesn't guarantee data consistency after a schema change - that is, if you add a new collection-property, existing records will have NULL-values for that property.
Patching all documents on load is the best I could come up with, and that doesn't feel right - I really wanted consistency at the schema-level, and unless I'm dealing with schema-less documents, there is no useful distinction between NULL and an empty collection; they're just two representations of the same thing.
How, or at what level do you deal with this?