ConventionRegistry.Register("IgnoreIfDefault",
new ConventionPack { new IgnoreIfDefaultConvention(true) },
_ => true);
var bsonDocument = anon.ToBsonDocument();
using IgnoreIfDefaultConvention can cause an unintended behavior due to the fact it affects all default values. For instance, values, as listed below, will not be saved:
int = 0
decimal = 0
bool = false
If I want to ignore only null values and Empty Arrays what is the best approach?