To support the use case of encoding Go structs as MongoDB documents, we will add an omitnil BSON struct tag that only omits nil values but includes empty values. The $push and $addToSet update operators work the same when modifying document fields that are empty arrays and document fields that do not exist (the only problem is document fields that are BSON null), so the behavior of omitnil maps well to that use case. Additionally, other MongoDB drivers (e.g. Java and Rust) offer a similar behaviors.
Definition of done:
- Add an omitnil BSON struct tag that only omits nil values but includes empty values.
- is related to
-
GODRIVER-2786 "bson.MarshalValue" does not support "any" value of "nil"
- Backlog
-
GODRIVER-2680 Prepare the Go Driver 1.x API for a smooth transition to the 2.0 API
- Development Complete
-
GODRIVER-2137 empty/nil slices create null field, which can't be used by various functions
- Backlog
- related to
-
GODRIVER-3427 Add a global "omitempty" flag
- Backlog
-
GODRIVER-2820 Consider exported and private struct fields for "Encoder.OmitZeroStruct"
- Backlog
-
GODRIVER-3224 Allow Zeroer to apply to more than just structs
- Backlog
-
GODRIVER-2920 Should empty bson.Raw follow the json.RawMessage encoding conventions?
- Backlog