Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Created by Guest
Created on Oct 25, 2020

BsonIgnoreIfEmpty - Property Attribute

Like BsonIgnoreIfDefault and BsonIgnoreIfNull, we can add BsonIgnoreIfEmpty. It can be added on IEnumerables (which we basically know they cannot have infinite values since it is inserted to db after all..) and if the IEnumerable is empty, it wont serialize it to the db BUT will know to put default value (an empty list for example) in said property. They will decrease below boilerplate code for IEnumerable: Serialization: Field = otherField?.count > 0 ? otherFIeld : null; Deserialization: otherField = Field ?? new List; Obviously, we can improve this code to also support Dictionary.