Skip to content

Commit

Permalink
provided examples in the changelog.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
Jibola committed Feb 1, 2024
1 parent e37ac41 commit fe2f7e0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,28 @@ Unavoidable breaking changes
:attr:`options.pool_options.metadata` is now of type ``dict`` as opposed to :class:`bson.son.SON`.
Here's an example of how this changes expected output::

>>> ...
# Before
>>> client.options.pool_options.metadata
SON([('driver', SON([('name', 'PyMongo'), ('version', '4.7.0.dev0')])), ('os', SON([('type', 'Darwin'), ('name', 'Darwin'), ('architecture', 'arm64'), ('version', '14.3')])), ('platform', 'CPython 3.11.6.final.0')])

# After
>>> client.options.pool_options.metadata
{'driver': {'name': 'PyMongo', 'version': '4.7.0.dev0'}, 'os': {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}, 'platform': 'CPython 3.11.6.final.0'}

# To convert from dict to SON
# This will only convert the first layer of the dictionary
>>> data_as_dict = client.options.pool_options.metadata
>>> SON(data_as_dict)
SON([('driver', {'name': 'PyMongo', 'version': '4.7.0.dev0'}), ('os', {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}), ('platform', 'CPython 3.11.6.final.0')])

# To convert from dict to SON on a nested dictionary
>>> def dict_to_SON(data_as_dict: dict[Any, Any]):
... data_as_SON = SON()
... for key, value in data_as_dict.items():
... data_as_SON[key] = dict_to_SON(value) if isinstance(value, dict) else value
... return data_as_SON
>>>
>>> dict_to_SON(data_as_dict)

Changes in Version 4.6.1
------------------------
Expand Down

0 comments on commit fe2f7e0

Please sign in to comment.