diff --git a/source/fundamentals/bson.txt b/source/fundamentals/bson.txt index 31fa3582..c003b632 100644 --- a/source/fundamentals/bson.txt +++ b/source/fundamentals/bson.txt @@ -74,8 +74,12 @@ use in the {+driver-short+}: - Description * - ``omitempty`` - - The field will not be marshalled if it is set to the zero value - corresponding to the field type. + - The field will not be marshaled if it is set to the zero value + corresponding to the field type. To globally prevent the driver from + marshaling fields set to a zero value, you can set the ``OmitEmpty`` + BSON option. To learn more about how to set the ``OmitEmpty`` BSON option, + see the example in the :ref:`BSON Options ` + section of this page. * - ``minsize`` - If the field is type ``int64``, ``uint``, ``uint32``, or ``uint64`` and @@ -211,6 +215,8 @@ the following rules: - Includes an empty ``lastname`` field - Stores the ``Address`` field as a nested value +.. _golang-bson-options: + BSON Options ------------ @@ -226,6 +232,8 @@ This example performs the following actions: to use the ``"json"`` struct tag if a ``"bson"`` struct tag is not specified - Sets the ``NilSliceAsEmpty`` field to ``true``, which instructs the driver to marshal ``nil`` Go slices as empty BSON arrays + - Sets the ``OmitEmpty`` field to ``true``, which instructs the driver to globally omit + empty values from the marshaled BSON, rather than set empty values to ``null`` - Passes the ``BSONOptions`` instance to the ``SetBSONOptions()`` helper method to specify a ``ClientOptions`` instance @@ -236,6 +244,7 @@ This example performs the following actions: bsonOpts := &options.BSONOptions { UseJSONStructTags: true, NilSliceAsEmpty: true, + OmitEmpty: true, } clientOpts := options.Client(). diff --git a/source/whats-new.txt b/source/whats-new.txt index dffe7a73..553f9749 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -26,6 +26,7 @@ What's New Learn what's new in: +* :ref:`Version 2.2 ` * :ref:`Version 2.1 ` * :ref:`Version 2.0 ` * :ref:`Version 1.17 ` @@ -37,6 +38,19 @@ Learn what's new in: * :ref:`Version 1.12.1 ` * :ref:`Version 1.12 ` +.. _golang-version-2.2: + +What's New in 2.2 +----------------- + +The 2.2 {+driver-short+} release includes the following improvements +and fixes: + +- Adds the ``OmitEmpty`` BSON option to globally prevent empty values from + being serialized. To learn more about setting the ``OmitEmpty`` global flag, + see the example in the :ref:`BSON Options ` section of the + BSON guide. + .. _golang-version-2.1: What's New in 2.1