Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions source/fundamentals/bson.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------

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

clientOpts := options.Client().
Expand Down
15 changes: 15 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,20 @@ 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.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<golang-bson-options>` section of the
BSON guide.

.. _golang-version-2.1:

What's New in 2.1
Expand Down
Loading