Updated
Support disabling bson helpers
Was
Writing a record to MongoDb from Databricks spark dataframe fails in a peculiar manner related to a null value in a nested column that has only a single value. Looking at the stack trace, it appears that the javascript codec gets chosen for nested structures that have only a single value. In turn, bson.AbstractBsonWriter.writeJavaScript will not accept null values and so fails.
If you look at the attached image, you will see nested, with only a single field, fails, whereas nested 2 succeeds.
Larger image along with full stack trace attached.