PYTHON-2748 Fix error in UUID example (#650)

(cherry picked from commit 00f7fe8ce3)
This commit is contained in:
Prashant Mital 2021-06-23 11:05:57 -07:00 committed by Prashant Mital
parent 1b2a599706
commit b03e5989c0
No known key found for this signature in database
GPG Key ID: 8EFE2B468F727B75

View File

@ -255,19 +255,27 @@ Applications can set the UUID representation in one of the following ways:
* - ``unspecified``
- :ref:`unspecified-representation-details`
#. Using the ``uuid_representation`` kwarg option, e.g.::
#. At the ``MongoClient`` level using the ``uuidRepresentation`` kwarg
option, e.g.::
from bson.binary import UuidRepresentation
client = MongoClient(uuid_representation=UuidRepresentation.PYTHON_LEGACY)
client = MongoClient(uuidRepresentation=UuidRepresentation.PYTHON_LEGACY)
#. By supplying a suitable :class:`~bson.codec_options.CodecOptions`
instance, e.g.::
#. At the ``Database`` or ``Collection`` level by supplying a suitable
:class:`~bson.codec_options.CodecOptions` instance, e.g.::
from bson.codec_options import CodecOptions
csharp_opts = CodecOptions(uuid_representation=UuidRepresentation.CSHARP_LEGACY)
java_opts = CodecOptions(uuid_representation=UuidRepresentation.JAVA_LEGACY)
# Get database/collection from client with csharpLegacy UUID representation
csharp_database = client.get_database('csharp_db', codec_options=csharp_opts)
csharp_collection = client.testdb.get_collection('csharp_coll', codec_options=csharp_opts)
# Get database/collection from existing database/collection with javaLegacy UUID representation
java_database = csharp_database.with_options(codec_options=java_opts)
java_collection = csharp_collection.with_options(codec_options=java_opts)
Supported UUID Representations
------------------------------