Skip to content

Commit 99101c2

Browse files
committed
RM feedback
1 parent af55816 commit 99101c2

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

source/data-formats/bson.txt

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ represents the preceding sample BSON document:
5252
.. code-block:: python
5353

5454
document = {
55-
'address': {
56-
'street': 'Pizza St',
57-
'zipcode': '10003'
55+
"address": {
56+
"street": "Pizza St",
57+
"zipcode": "10003"
5858
},
59-
'coord': [-73.982419, 41.579505],
60-
'cuisine': 'Pizza',
61-
'name': 'Mongo's Pizza'
59+
"coord": [-73.982419, 41.579505],
60+
"cuisine": "Pizza",
61+
"name": "Mongo's Pizza"
6262
}
6363

6464
Change a BSON Document
@@ -70,39 +70,36 @@ BSON document:
7070

7171
1. Adds a new field, ``restaurant_id``, with the value ``12345``
7272
#. Removes the ``cuisine`` field
73-
#. Sets the value of the ``name`` field to ``'Mongo's Pizza Place'``
73+
#. Sets the value of the ``name`` field to ``"Mongo's Pizza Place"``
7474

7575
.. code-block:: python
7676

77-
document['restaurant_id'] = 12345
78-
del document['cuisine']
79-
document['name'] = 'Mongo's Pizza Place'
77+
document["restaurant_id"] = 12345
78+
del document["cuisine"]
79+
document["name"] = "Mongo's Pizza Place"
8080

8181
Write BSON to a File
8282
--------------------
8383

84-
To write BSON data to a file, perform the following steps:
85-
86-
1. Fetch the documents you want to write to a file.
87-
#. Open a file stream on the file to write to in write-binary mode.
88-
#. Write each document to the output file. Ensure that documents are encoded to BSON
89-
format by using the ``BSON.encode()`` method.
84+
To write BSON data to a file, open a file stream to in write-binary mode on the output file.
85+
Then, write each document to the output file. Ensure that documents are encoded in BSON
86+
format by using the ``BSON.encode()`` method.
9087

9188
The following example writes the sample BSON document to ``file.bson``:
9289

9390
.. code-block:: python
9491

9592
import bson
9693

97-
with open('file.bson', 'w') as file:
94+
with open("file.bson", "w") as file:
9895
file.write(BSON.encode(document))
9996

10097
Read BSON from a File
10198
---------------------
10299

103-
To read BSON documents from a file, open a file stream on the file to read from in
104-
read-binary mode, then read the documents from the file. Ensure that the documents are
105-
decoded from BSON format by using the ``BSON.decode()`` method.
100+
To read BSON documents from a file, open a file stream in read-binary mode on the input
101+
file. Then, decode the documents from BSON format as you read them by using the ``BSON.decode()``
102+
method.
106103

107104
The following example reads the sample BSON document from ``file.bson``:
108105

@@ -112,20 +109,18 @@ The following example reads the sample BSON document from ``file.bson``:
112109
.. input::
113110
:language: python
114111

115-
with open('file.bson', 'rb') as file:
112+
with open("file.bson", "rb") as file:
116113
data = file.read()
117114
document = BSON(data).decode()
118115
print(document)
119116

120117
.. output::
121118
:visible: false
122119

123-
{'address': {'street': 'Pizza St', 'zipcode': '10003'}, 'coord': [-73.982419, 41.579505], 'cuisine': 'Pizza', 'name': "Mongo's Pizza"}
120+
{"address": {"street": "Pizza St", "zipcode": "10003"}, "coord": [-73.982419, 41.579505], "cuisine": "Pizza", "name": "Mongo's Pizza"}
124121

125122
API Documentation
126123
-----------------
127124

128125
To learn more about any of the methods or types discussed in this
129-
guide, see the following API documentation:
130-
131-
- `bson <{+api-root+}bson/index.html>`__
126+
guide, see the `bson <{+api-root+}bson/index.html>`__ API documentation.

0 commit comments

Comments
 (0)