@@ -74,8 +74,12 @@ use in the {+driver-short+}:
74
74
- Description
75
75
76
76
* - ``omitempty``
77
- - The field will not be marshalled if it is set to the zero value
78
- corresponding to the field type.
77
+ - The field will not be marshaled if it is set to the zero value
78
+ corresponding to the field type. To globally prevent the driver from
79
+ marshaling fields set to a zero value, you can set the ``OmitEmpty``
80
+ BSON option. To learn more about how to set the ``OmitEmpty`` BSON option,
81
+ see the example in the :ref:`BSON Options <golang-bson-options>`
82
+ section of this page.
79
83
80
84
* - ``minsize``
81
85
- If the field is type ``int64``, ``uint``, ``uint32``, or ``uint64`` and
@@ -211,6 +215,8 @@ the following rules:
211
215
- Includes an empty ``lastname`` field
212
216
- Stores the ``Address`` field as a nested value
213
217
218
+ .. _golang-bson-options:
219
+
214
220
BSON Options
215
221
------------
216
222
@@ -226,6 +232,8 @@ This example performs the following actions:
226
232
to use the ``"json"`` struct tag if a ``"bson"`` struct tag is not specified
227
233
- Sets the ``NilSliceAsEmpty`` field to ``true``, which instructs the driver
228
234
to marshal ``nil`` Go slices as empty BSON arrays
235
+ - Sets the ``OmitEmpty`` field to ``true``, which instructs the driver to globally omit
236
+ empty values from the marshaled BSON, rather than set empty values to ``null``
229
237
230
238
- Passes the ``BSONOptions`` instance to the ``SetBSONOptions()`` helper method to specify
231
239
a ``ClientOptions`` instance
@@ -236,6 +244,7 @@ This example performs the following actions:
236
244
bsonOpts := &options.BSONOptions {
237
245
UseJSONStructTags: true,
238
246
NilSliceAsEmpty: true,
247
+ OmitEmpty: true,
239
248
}
240
249
241
250
clientOpts := options.Client().
0 commit comments