@@ -40,12 +40,13 @@ The following code block shows an example GUID:
40
40
.. code-block::
41
41
:copyable: false
42
42
43
- 00112233-4455-6677-8899-aabbccddeeff
43
+ 00112233-4455-6677-8899-aabbccddeeff
44
44
45
45
Originally, MongoDB represented GUIDs as ``BsonBinaryData``
46
46
values of :manual:`subtype 3. </reference/bson-types/#binary-data>`
47
47
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.
49
50
50
51
The following tabs show different driver encodings of the preceding GUID to
51
52
``BsonBinaryData`` subtype 3:
@@ -119,10 +120,26 @@ members and the corresponding ``BsonBinaryData`` subtypes:
119
120
* - ``Unspecified``
120
121
- N/A
121
122
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
123
139
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);
126
143
127
144
The following sections describe the ways in which you can configure GUID representation
128
145
in your application.
@@ -227,4 +244,4 @@ guide, see the following API documentation:
227
244
- `BsonGuidRepresentation <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Attributes.BsonGuidRepresentationAttribute.html>`__
228
245
- `GuidSerializer <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Serializers.GuidSerializer.html>`__
229
246
- `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>`__
0 commit comments