Skip to content

Commit d0b4a6a

Browse files
committed
DOCSP-44433: Compare BSON::Binary objects
1 parent 88c9d5c commit d0b4a6a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Diff for: source/data-formats/bson.txt

+9-5
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,16 @@ specific to the specification:
227227
``BSON::Binary``
228228
~~~~~~~~~~~~~~~~
229229

230-
Use ``BSON::Binary`` objects to store arbitrary binary data. The ``Binary``
231-
objects can be constructed from binary strings as follows:
230+
Use ``BSON::Binary`` objects to store arbitrary binary data. You can construct
231+
``Binary`` objects from binary strings, as shown in the following code:
232232

233233
.. code-block:: ruby
234234

235235
BSON::Binary.new("binary_string")
236236
# => <BSON::Binary:0x47113101192900 type=generic data=0x62696e6172795f73...>
237237

238238
By default, ``Binary`` objects are created with BSON binary subtype 0
239-
(``:generic``). The subtype can be explicitly specified to indicate that
239+
(``:generic``). You can explicitly specify the subtype to indicate that
240240
the bytes encode a particular type of data:
241241

242242
.. code-block:: ruby
@@ -247,8 +247,8 @@ the bytes encode a particular type of data:
247247
Valid subtypes are ``:generic``, ``:function``, ``:old``, ``:uuid_old``,
248248
``:uuid``, ``:md5`` and ``:user``.
249249

250-
The data and the subtype can be retrieved from ``Binary`` instances using
251-
``data`` and ``type`` attributes, as follows:
250+
You can use the ``data`` and ``type`` attributes to retrieve a
251+
``Binary`` object's data and the subtype, as shown in the following code:
252252

253253
.. code-block:: ruby
254254

@@ -258,6 +258,10 @@ The data and the subtype can be retrieved from ``Binary`` instances using
258258
binary.type
259259
=> :user
260260

261+
You can compare ``Binary`` objects by using the ``<=>`` operator, which allows
262+
you to sort objects that have the same binary subtype. To compare ``Binary`` objects,
263+
ensure that you install v5.0.2 or later of the BSON library.
264+
261265
.. note::
262266

263267
``BSON::Binary`` objects always store the data in ``BINARY`` encoding,

0 commit comments

Comments
 (0)