From 2c444d8216962abbd657f0e5b6d51fb8d180c20c Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 17 Mar 2025 17:38:37 -0400 Subject: [PATCH 1/7] DOCSP-48090 OmitEmpty global flag --- source/fundamentals/bson.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/fundamentals/bson.txt b/source/fundamentals/bson.txt index 31fa3582..fb35f18b 100644 --- a/source/fundamentals/bson.txt +++ b/source/fundamentals/bson.txt @@ -226,6 +226,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 +238,7 @@ This example performs the following actions: bsonOpts := &options.BSONOptions { UseJSONStructTags: true, NilSliceAsEmpty: true, + OmitEmpty: true, } clientOpts := options.Client(). From 01af806890428fa5b74048f23e374d18a3e6e4ff Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 17 Mar 2025 18:09:55 -0400 Subject: [PATCH 2/7] build fail --- source/fundamentals/bson.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/fundamentals/bson.txt b/source/fundamentals/bson.txt index fb35f18b..11a5ffc2 100644 --- a/source/fundamentals/bson.txt +++ b/source/fundamentals/bson.txt @@ -227,7 +227,7 @@ This example performs the following actions: - 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 + 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 From bf82344b4e3cf28dafb4e16f5f483b5600c5f0f6 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Tue, 18 Mar 2025 11:13:44 -0400 Subject: [PATCH 3/7] netlify still failing --- source/fundamentals/bson.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/fundamentals/bson.txt b/source/fundamentals/bson.txt index 11a5ffc2..9372c1f9 100644 --- a/source/fundamentals/bson.txt +++ b/source/fundamentals/bson.txt @@ -227,7 +227,7 @@ This example performs the following actions: - 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`` + 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 From 3986618f562d814edc7ce1b2c9ff88c095469f48 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Tue, 18 Mar 2025 15:03:33 -0400 Subject: [PATCH 4/7] RR comments --- source/fundamentals/bson.txt | 2 ++ source/whats-new.txt | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/source/fundamentals/bson.txt b/source/fundamentals/bson.txt index 9372c1f9..5bfc710c 100644 --- a/source/fundamentals/bson.txt +++ b/source/fundamentals/bson.txt @@ -211,6 +211,8 @@ the following rules: - Includes an empty ``lastname`` field - Stores the ``Address`` field as a nested value +.. _golang-bson-options: + BSON Options ------------ diff --git a/source/whats-new.txt b/source/whats-new.txt index dffe7a73..ccae5fa0 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,20 @@ Learn what's new in: * :ref:`Version 1.12.1 ` * :ref:`Version 1.12 ` +.. _golang-version-2.2: + +What's New in 2.1 +----------------- + +The 2.2 {+driver-short+} release includes the following improvements +and fixes: + +- Adds a new ``OmitEmpty`` global flag to globally omit empty values from + marshaled BSON. This prevents the driver from writing null values for fields + with empty values. For more information on 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 From 3971c4498d8fe6011e32e0e70400e3d45419b27f Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Tue, 18 Mar 2025 16:30:27 -0400 Subject: [PATCH 5/7] RR comments --- source/whats-new.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/whats-new.txt b/source/whats-new.txt index ccae5fa0..9619b8f8 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -40,16 +40,15 @@ Learn what's new in: .. _golang-version-2.2: -What's New in 2.1 +What's New in 2.2 ----------------- The 2.2 {+driver-short+} release includes the following improvements and fixes: -- Adds a new ``OmitEmpty`` global flag to globally omit empty values from - marshaled BSON. This prevents the driver from writing null values for fields - with empty values. For more information on setting the ``OmitEmpty`` global flag, - see the example in the :ref:`BSON Options` section of the +- Adds the ``OmitEmpty`` global flag to globally omit empty values from + being serialized. For more information on setting the ``OmitEmpty`` global flag, + see the example in the :ref:`BSON Options ` section of the BSON guide. .. _golang-version-2.1: From 444268fb9f2ac8b698ab0c615741b21ea2d528c1 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Tue, 18 Mar 2025 16:39:27 -0400 Subject: [PATCH 6/7] add link to the BSON options section --- source/fundamentals/bson.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/fundamentals/bson.txt b/source/fundamentals/bson.txt index 5bfc710c..9b0a7e97 100644 --- a/source/fundamentals/bson.txt +++ b/source/fundamentals/bson.txt @@ -75,7 +75,10 @@ use in the {+driver-short+}: * - ``omitempty`` - The field will not be marshalled if it is set to the zero value - corresponding to the field type. + corresponding to the field type. To learn more about how to globally + omit fields with zero values by using 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 From a3baba0fe183163fd48925c05057c03df1235d7e Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Mar 2025 12:34:17 -0400 Subject: [PATCH 7/7] RR feedback --- source/fundamentals/bson.txt | 11 ++++++----- source/whats-new.txt | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/fundamentals/bson.txt b/source/fundamentals/bson.txt index 9b0a7e97..c003b632 100644 --- a/source/fundamentals/bson.txt +++ b/source/fundamentals/bson.txt @@ -74,11 +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. To learn more about how to globally - omit fields with zero values by using the ``OmitEmpty`` BSON option, - see the example in the :ref:`BSON Options ` section - of this page. + - 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 diff --git a/source/whats-new.txt b/source/whats-new.txt index 9619b8f8..553f9749 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -46,8 +46,8 @@ What's New in 2.2 The 2.2 {+driver-short+} release includes the following improvements and fixes: -- Adds the ``OmitEmpty`` global flag to globally omit empty values from - being serialized. For more information on setting the ``OmitEmpty`` global flag, +- 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.