@@ -24,6 +24,88 @@ implements the `mongo extension <http://php.net/mongo>`_ API using this library
24
24
and the new driver. While this adapter library is not officially supported by
25
25
MongoDB, it does bear mentioning.
26
26
27
+ BSON Type Classes
28
+ -----------------
29
+
30
+ When upgrading from the legacy driver,
31
+ `type classes <https://www.php.net/manual/en/mongo.types.php>`_ such as
32
+ :php:`MongoId <mongoid>` must be replaced with classes in the
33
+ `MongoDB\\BSON namespace <https://www.php.net/manual/en/book.bson.php>`_. The
34
+ new driver also introduces interfaces for its BSON types, which should be
35
+ preferred if applications need to type hint against BSON values.
36
+
37
+ The following table lists all legacy classes alongside the equivalent class in
38
+ the new driver.
39
+
40
+ .. list-table::
41
+ :header-rows: 1
42
+
43
+ * - Legacy class
44
+ - BSON type class
45
+ - BSON type interface
46
+
47
+ * - :php:`MongoId <mongoid>`
48
+ - :php:`MongoDB\\BSON\\ObjectId <mongodb_bson_objectid>`
49
+ - :php:`MongoDB\\BSON\\ObjectIdInterface <mongodb_bson_objectidinterface>`
50
+
51
+ * - :php:`MongoCode <mongocode>`
52
+ - :php:`MongoDB\\BSON\\Javascript <mongodb_bson_javascript>`
53
+ - :php:`MongoDB\\BSON\\JavascriptInterface <mongodb_bson_javascriptinterface>`
54
+
55
+ * - :php:`MongoDate <mongodate>`
56
+ - :php:`MongoDB\\BSON\\UTCDateTime <mongodb_bson_utcdatetime>`
57
+ - :php:`MongoDB\\BSON\\UTCDateTimeInterface <mongodb_bson_utcdatetimeinterface>`
58
+
59
+ * - :php:`MongoRegex <mongoregex>`
60
+ - :php:`MongoDB\\BSON\\Regex <mongodb_bson_regex>`
61
+ - :php:`MongoDB\\BSON\\RegexInterface <mongodb_bson_regexinterface>`
62
+
63
+ * - :php:`MongoBinData <mongobindata>`
64
+ - :php:`MongoDB\\BSON\\Binary <mongodb_bson_binary>`
65
+ - :php:`MongoDB\\BSON\\BinaryInterface <mongodb_bson_binaryinterface>`
66
+
67
+ * - :php:`MongoInt32 <mongoint32>`
68
+ - Not implemented. [1]_
69
+ -
70
+
71
+ * - :php:`MongoInt64 <mongoint64>`
72
+ - :php:`MongoDB\\BSON\\Int64 <mongodb_bson_int64>`
73
+ - Not implemented. [2]_
74
+
75
+ * - :php:`MongoDBRef <mongodbref>`
76
+ - Not implemented. [3]_
77
+ -
78
+
79
+ * - :php:`MongoMinKey <mongominkey>`
80
+ - :php:`MongoDB\\BSON\\MinKey <mongodb_bson_minkey>`
81
+ - :php:`MongoDB\\BSON\\MinKeyInterface <mongodb_bson_minkeyinterface>`
82
+
83
+ * - :php:`MongoMaxKey <mongomaxkey>`
84
+ - :php:`MongoDB\\BSON\\MaxKey <mongodb_bson_maxkey>`
85
+ - :php:`MongoDB\\BSON\\MaxKeyInterface <mongodb_bson_maxkeyinterface>`
86
+
87
+ * - :php:`MongoTimestamp <mongotimestamp>`
88
+ - :php:`MongoDB\\BSON\\Timestamp <mongodb_bson_timestamp>`
89
+ - :php:`MongoDB\\BSON\\TimestampInterface <mongodb_bson_timestampinterface>`
90
+
91
+ .. [1] The new driver does not implement an equivalent class for
92
+ :php:`MongoInt32 <mongoint32>`. When decoding BSON, 32-bit integers will
93
+ always be represented as a PHP integer. When encoding BSON, PHP integers will
94
+ encode as either a 32-bit or 64-bit integer depending on their value.
95
+
96
+ .. [2] :php:`MongoDB\\BSON\\Int64 <mongodb_bson_int64>` does not have an
97
+ interface defined. The new driver does not allow applications to instantiate
98
+ this type (i.e. its constructor is private) and it is only created during
99
+ BSON decoding when a 64-bit integer cannot be represented as a PHP integer on
100
+ a 32-bit platform.
101
+
102
+ .. [3] The new driver does not implement an equivalent class for
103
+ :php:`MongoDBRef <mongodbref>` since
104
+ :manual:`DBRefs </reference/database-references>` are merely a BSON document
105
+ with a particular structure and not a proper BSON type. The new driver also
106
+ does not provide any helpers for working with DBRef objects, since their use
107
+ is not encouraged.
108
+
27
109
Collection API
28
110
--------------
29
111
0 commit comments