@@ -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+
2861The 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
4578You 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
5080represents the preceding sample BSON document:
5181
5282.. code-block:: python
@@ -65,7 +95,7 @@ Change a BSON Document
6595----------------------
6696
6797You 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
6999BSON document:
70100
711011. Adds a new field, ``restaurant_id``, with the value ``12345``
0 commit comments