Skip to content

Commit c72de53

Browse files
committed
DOCSP-50559: query guids (#646)
* DOCSP-50559: query guids * RB restructure * RB small fix (cherry picked from commit 004a229)
1 parent 57f1f71 commit c72de53

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

source/fundamentals/serialization/guid-serialization.txt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ The following code block shows an example GUID:
4040
.. code-block::
4141
:copyable: false
4242

43-
00112233-4455-6677-8899-aabbccddeeff
43+
00112233-4455-6677-8899-aabbccddeeff
4444

4545
Originally, MongoDB represented GUIDs as ``BsonBinaryData``
4646
values of :manual:`subtype 3. </reference/bson-types/#binary-data>`
4747
Because subtype 3 didn't standardize the byte order of GUIDs
48-
during encoding, different MongoDB drivers encoded GUIDs with different byte orders.
48+
during encoding, different MongoDB drivers encoded GUIDs with different
49+
byte orders.
4950

5051
The following tabs show different driver encodings of the preceding GUID to
5152
``BsonBinaryData`` subtype 3:
@@ -119,10 +120,26 @@ members and the corresponding ``BsonBinaryData`` subtypes:
119120
* - ``Unspecified``
120121
- N/A
121122

122-
.. note::
123+
The ``CSharpLegacy``, ``JavaLegacy``, and ``PythonLegacy`` GUID
124+
representations are all equivalent to ``BsonBinaryData`` subtype 3, but
125+
use different byte orders.
126+
127+
.. _csharp-guid-legacy-construct:
128+
129+
.. note:: Construct Legacy GUIDs
130+
131+
To construct legacy (subtype 3) GUID values, you must use the
132+
``BsonBinaryData()`` constructor to explicitly specify the legacy GUID
133+
type by passing the ``GuidRepresentation.CSharpLegacy`` parameter. The
134+
following code demonstrates how to create a legacy GUID to use in a
135+
query filter:
136+
137+
.. code-block:: csharp
138+
:emphasize-lines: 2
123139

124-
The ``CSharpLegacy``, ``JavaLegacy``, and ``PythonLegacy`` GUID representations are
125-
all equivalent to ``BsonBinaryData`` subtype 3, but use different byte orders.
140+
var guid = new Guid("00112233-4455-6677-8899-aabbccddeeff");
141+
var legacyGuid = new BsonBinaryData(guid, GuidRepresentation.CSharpLegacy);
142+
var filter = new BsonDocument("legacyGuidField", legacyGuid);
126143

127144
The following sections describe the ways in which you can configure GUID representation
128145
in your application.
@@ -227,4 +244,4 @@ guide, see the following API documentation:
227244
- `BsonGuidRepresentation <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Attributes.BsonGuidRepresentationAttribute.html>`__
228245
- `GuidSerializer <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Serializers.GuidSerializer.html>`__
229246
- `ObjectSerializer <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Serializers.ObjectSerializer.html>`__
230-
- `GuidRepresentation <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.GuidRepresentation.html>`__
247+
- `GuidRepresentation <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.GuidRepresentation.html>`__

source/upgrade/v3.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@ Version 3.0 Breaking Changes
111111
In version 3.0, ``GuidRepresentationMode.V3`` is the only supported mode. This change
112112
has the following effects on the driver:
113113

114-
- The ``BsonBinaryData(Guid)`` constructor has been removed. To construct a ``BsonBinaryData``
115-
object from a GUID, use the ``BsonBinaryData.Create(Guid, GuidRepresentation)`` constructor.
116-
- The ``BsonBinaryData.GuidRepresentation`` property has been removed.
114+
- The ``BsonBinaryData(Guid)`` constructor has been removed. To
115+
construct a ``BsonBinaryData`` object from a GUID, use the
116+
``BsonBinaryData.Create(Guid, GuidRepresentation)`` constructor. To
117+
view an example of creating a legacy GUID, see the :ref:`Construct
118+
Legacy GUIDs <csharp-guid-legacy-construct>` note in the GUID
119+
Serialization guide.
120+
- The ``BsonBinaryData.GuidRepresentation`` property has been removed.
117121
- You can call the ``BsonBinaryData.ToGuid()`` method only on ``BsonBinaryData``
118122
objects of subtype 4. If the object has any other subtype, you must call the
119123
``BsonBinaryData.ToGuid(GuidRepresentation)`` method and specify the subtype.
@@ -257,4 +261,5 @@ Version 3.0 Breaking Changes
257261
configure ``GUID`` serialization on a case-by-case basis without registering a global
258262
``GuidSerializer``.
259263

260-
To learn more about GUID serialization, see the :ref:`csharp-guids` guide.
264+
To learn more about GUID serialization, see the :ref:`csharp-guids`
265+
guide.

0 commit comments

Comments
 (0)