Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion source/fundamentals/bson.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <golang-bson-options>` section
of this page.

* - ``minsize``
- If the field is type ``int64``, ``uint``, ``uint32``, or ``uint64`` and
Expand Down Expand Up @@ -211,6 +214,8 @@ the following rules:
- Includes an empty ``lastname`` field
- Stores the ``Address`` field as a nested value

.. _golang-bson-options:

BSON Options
------------

Expand All @@ -226,6 +231,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
Expand All @@ -236,6 +243,7 @@ This example performs the following actions:
bsonOpts := &options.BSONOptions {
UseJSONStructTags: true,
NilSliceAsEmpty: true,
OmitEmpty: true,
}

clientOpts := options.Client().
Expand Down
14 changes: 14 additions & 0 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ What's New

Learn what's new in:

* :ref:`Version 2.2 <golang-version-2.2>`
* :ref:`Version 2.1 <golang-version-2.1>`
* :ref:`Version 2.0 <golang-version-2.0>`
* :ref:`Version 1.17 <golang-version-1.17>`
Expand All @@ -37,6 +38,19 @@ Learn what's new in:
* :ref:`Version 1.12.1 <version-1.12.1>`
* :ref:`Version 1.12 <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`` 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 <golang-bson-options>` section of the
BSON guide.

.. _golang-version-2.1:

What's New in 2.1
Expand Down
Loading