[GODRIVER-2765] Add an "omitnil" BSON struct tag Created: 02/Mar/23  Updated: 09/Jan/24

Status: Backlog
Project: Go Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-2920 Should empty bson.Raw follow the json... Backlog
is related to GODRIVER-2786 "bson.MarshalValue" does not support ... Backlog
is related to GODRIVER-2680 Prepare the Go Driver 1.x API for a s... Closed
is related to GODRIVER-2137 empty/nil slices create null field, w... Backlog
Quarter: FY25Q1
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

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.

Generated at Thu Feb 08 08:39:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.