Skip to content

Commit b690bc4

Browse files
committed
DOCSP-48322: BSON tech feedback (#225)
(cherry picked from commit b1be525)
1 parent 827a942 commit b690bc4

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

source/data-formats/bson.txt

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,39 @@ binary data. You can use BSON documents in your {+language+} application by incl
2525
`bson <{+api-root+}bson/index.html>`__ package. For a complete list of supported types, see the
2626
:manual:`BSON Types </reference/bson-types>` server manual page.
2727

28+
BSON documents are stored in MongoDB collections in binary format, while {+driver-short+}
29+
represents BSON documents as {+language+} dictionaries. {+driver-short+} automatically
30+
converts {+language+} dictionaries into BSON documents when inserting them into a collection.
31+
Likewise, when you retrieve a document from a collection, {+driver-short+} converts the BSON
32+
document back into a {+language+} dictionary.
33+
34+
The following example shows a document in both dictionary and BSON formats. Use the
35+
:guilabel:`Dictionary` or :guilabel:`BSON` tab to see the corresponding format:
36+
37+
.. tabs::
38+
39+
.. tab:: Dictionary
40+
:tabid: dict
41+
42+
.. code-block:: python
43+
44+
{"hello": "world"}
45+
46+
.. tab:: BSON
47+
:tabid: bson
48+
49+
.. code-block:: none
50+
51+
\x16\x00\x00\x00 # total document size
52+
\x02 # 0x02 = type String
53+
hello\x00 # field name
54+
\x06\x00\x00\x00world\x00 # field value
55+
\x00 # 0x00 = type EOO ("end of object")
56+
57+
58+
Sample Data
59+
~~~~~~~~~~~
60+
2861
The code samples in this guide use the following BSON document as an example:
2962

3063
.. code-block:: none
@@ -43,10 +76,7 @@ Create a BSON Document
4376
----------------------
4477

4578
You can create a BSON document by using the same notation you use to create a
46-
dictionary in {+language+}. {+driver-short+} automatically converts {+language+} dictionaries
47-
into BSON documents when inserting them into a collection.
48-
49-
The following example creates a BSON document that
79+
dictionary in {+language+}. The following example creates a BSON document that
5080
represents the preceding sample BSON document:
5181

5282
.. code-block:: python
@@ -65,7 +95,7 @@ Change a BSON Document
6595
----------------------
6696

6797
You can modify the contents of a BSON document by using the same notation you use to modify
68-
a dictionary in {+language+}. The following example makes three changes to the previous
98+
a dictionary in {+language+}. The following example makes three changes to the sample
6999
BSON document:
70100

71101
1. Adds a new field, ``restaurant_id``, with the value ``12345``

0 commit comments

Comments
 (0)