@@ -41,66 +41,26 @@ created ``BsonBinaryData`` subtype 4.
41
41
42
42
Use ``BsonBinaryData`` subtype 4 for all new GUIDs.
43
43
44
- GuidRepresentationMode
45
- ----------------------
46
44
47
45
In many MongoDB collections, all GUID fields use the same subtype of ``BsonBinaryData``.
48
46
Some older collections, however, may contain some GUID fields that
49
47
use subtype 3 and others that use subtype 4.
50
- To ensure that the driver serializes and deserializes all GUIDs correctly,
51
- you should set the ``BsonDefaults.GuidRepresentationMode`` property to one of the
52
- following ``GuidRepresentationMode`` values:
53
-
54
- V2
55
- ~~
56
-
57
- ``GuidRepresentationMode.V2`` assumes that all GUIDs in a document use the same
58
- ``BsonBinaryData`` subtype. In this mode, GUID representation is
59
- controlled by the reader or writer, not the serializer.
60
-
61
- ``V2`` is the default ``GuidRepresentationMode``.
62
-
63
- .. note::
64
-
65
- When version 3 of the {+driver-short+} is released, support for ``GuidRepresentationMode.V2``
66
- will be removed from the driver and ``V3`` will become the default.
67
-
68
- V3
69
- ~~
70
48
71
- ``GuidRepresentationMode.V3`` allows fields in the same document to use different
72
- GUID formats.
73
- In this mode, GUID representation is controlled at the property level by configuring the
49
+ The driver allows fields in the same document to use different
50
+ GUID formats. GUID representation is controlled at the property level by configuring the
74
51
serializer for each property.
75
52
76
- To use ``GuidRepresentationMode.V3``, run the following line of code. You should run this
77
- code during the bootstrapping phase of your application, before creating
78
- a ``MongoClient`` object.
53
+ Serializing GUIDs
54
+ -----------------
79
55
80
- .. code-block:: csharp
81
-
82
- BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;
83
-
84
- Running in ``V3`` mode changes the behavior of the driver in the following ways:
85
-
86
- - The ``BsonBinaryReader.ReadBinaryData()`` method ignores ``readerSettings.GuidRepresentation``
87
- - The ``BsonBinaryWriter.WriteBinaryData()`` method ignores ``writerSettings.GuidRepresentation``
88
- - The ``JsonReader.ReadBinaryData()`` method ignores ``readerSettings.GuidRepresentation``
89
- - ``JsonWriter`` ignores ``writerSettings.GuidRepresentation``
90
- - Calling the ``BsonBinaryData.ToGuid()`` method without the ``GuidRepresentation``
91
- parameter works only on GUIDs of subtype 4.
56
+ The driver handles GUID serialization at the level of individual
57
+ properties. You must ensure that
58
+ each GUID field is serialized and deserialized correctly.
92
59
93
60
.. note::
94
61
95
- You can't use both ``GuidRepresentationMode.V2`` and ``GuidRepresentationMode.V3``
96
- in a single application.
97
-
98
- Serializing GUIDs in V3
99
- -----------------------
100
-
101
- ``GuidRepresentationMode.V3`` handles GUID serialization at the level of individual
102
- properties. This mode is more flexible than ``V2``, but it also means you must ensure that
103
- each GUID field is serialized and deserialized correctly.
62
+ Default value is unspecified. Driver throws an exception rather than guessing.
63
+ You must specify the format for every GUID, or globally register a serializer.
104
64
105
65
If you're using the {+driver-short+} to :ref:`automap your {+language+} classes to document schemas <csharp-class-mapping>`,
106
66
you can use the ``BsonGuidRepresentation`` attribute on a GUID property
@@ -150,12 +110,12 @@ in your application, such as during the bootstrapping phase:
150
110
serializer for the most commonly used GUID subtype, then use the ``BsonGuidRepresentation``
151
111
attribute to denote any GUID properties of another subtype.
152
112
153
- Serializing Objects in V3
154
- -------------------------
113
+ Serializing Objects
114
+ -------------------
155
115
156
116
You can use an ``ObjectSerializer`` to serialize hierarchical objects to subdocuments.
157
- To ensure that GUIDs in these objects are serialized and deserialized correctly when using
158
- ``V3``, you should select the correct GUID representation when constructing your
117
+ To ensure that GUIDs in these objects are serialized and deserialized correctly,
118
+ you should select the correct GUID representation when constructing your
159
119
``ObjectSerializer``.
160
120
161
121
The following code sample shows how to
0 commit comments