Using the following schema:
{
data1: String,
nested: {
nestedProp1: String,
nestedSub: [String]
}
}
When I do new MyModel({data1: 'something}).toObject()
shows the newly created document like this:
{
'_id' : 'xxxxx',
'data1': 'something',
'nested': {
'nestedSub': []
}
}
I.e. the nested document is created with the empty array.
How do I make "nested" to be fully optional - i.e. not created at all if it is not provided on the input data?
I do not want to use a separate schema for the "nested", no need of that complexity.