Skip to content

Commit 39799a5

Browse files
DOCSP-47173 - Remove FAQs (#175)
Co-authored-by: Jordan Smith <[email protected]>
1 parent 052b97b commit 39799a5

File tree

13 files changed

+310
-452
lines changed

13 files changed

+310
-452
lines changed

config/redirects

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ raw: ${prefix}/master -> ${base}/upcoming/
1212
raw: ${prefix}/get-started/download-and-install/ -> ${base}/current/get-started/download-and-install/
1313

1414
[*-master]: ${prefix}/${version}/security/enterprise-authentication/ -> ${base}/${version}/security/authentication/
15-
[*-master]: ${prefix}/${version}/connect/connection-pools/ -> ${base}/${version}/connect/connection-options/#connection-pools
15+
[*-master]: ${prefix}/${version}/faq/ -> ${base}/${version}/
16+
[*-master]: ${prefix}/${version}/connect/connection-pools/ -> ${base}/${version}/connect/connection-options/#connection-pools

source/compatibility.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,4 @@ The following compatibility table specifies the recommended version of
4848
{+driver-short+} for use with a specific version of Python.
4949
The first column lists the driver version.
5050

51-
.. include:: /includes/language-compatibility-table-pymongo.rst
52-
53-
For more information on how to read the compatibility tables, see our guide on
54-
:ref:`MongoDB Compatibility Tables. <about-driver-compatibility>`
51+
.. include:: /includes/language-compatibility-table-pymongo.rst

source/connect/mongoclient.txt

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,60 @@ constructor accepts. All parameters are optional.
168168

169169
**Data type:** `TypeRegistry <{+api-root+}bson/codec_options.html#bson.codec_options.TypeRegistry>`__
170170

171-
.. tip:: Reusing Your Client
171+
Concurrent Execution
172+
--------------------
172173

173-
Because each ``MongoClient`` object represents a pool of connections to the
174-
database, most applications require only a single instance of
175-
``MongoClient``, even across multiple requests. However, if you fork
176-
a process, the child process *does* need its own ``MongoClient`` object.
177-
To learn more, see the :ref:`FAQ <pymongo-faq>` page.
174+
The following sections describe {+driver-short+}'s support for concurrent execution
175+
mechanisms.
176+
177+
Multithreading
178+
~~~~~~~~~~~~~~
179+
180+
{+driver-short+} is thread-safe and provides built-in connection pooling
181+
for threaded applications.
182+
Because each ``MongoClient`` object represents a pool of connections to the
183+
database, most applications require only a single instance of
184+
``MongoClient``, even across multiple requests.
185+
186+
.. _pymongo-forks:
187+
188+
Multiple Forks
189+
~~~~~~~~~~~~~~~
190+
191+
{+driver-short+} supports calling the ``fork()`` method to create a new process.
192+
However, if you fork a process, you must create a new ``MongoClient`` instance in the
193+
child process.
194+
195+
.. important:: Don't Pass a MongoClient to a Child Process
196+
197+
If you use the ``fork()`` method to create a new process, don't pass an instance
198+
of the ``MongoClient`` class from the parent process to the child process. This creates
199+
a high probability of deadlock among ``MongoClient`` instances in the child process.
200+
{+driver-short+} tries to issue a warning if this deadlock might occur.
201+
202+
Multiprocessing
203+
~~~~~~~~~~~~~~~
204+
205+
{+driver-short+} supports the Python ``multiprocessing`` module.
206+
However, on Unix systems, the multiprocessing module spawns processes by using
207+
the ``fork()`` method. This carries the same risks described in :ref:`<pymongo-forks>`
208+
209+
To use multiprocessing with {+driver-short+}, write code similar to the following example:
210+
211+
.. code-block:: python
212+
213+
# Each process creates its own instance of MongoClient.
214+
def func():
215+
db = pymongo.MongoClient().mydb
216+
# Do something with db.
217+
218+
proc = multiprocessing.Process(target=func)
219+
proc.start()
220+
221+
.. important::
222+
223+
Do not copy an instance of the ``MongoClient`` class from the parent process to a child
224+
process.
178225

179226
Type Hints
180227
----------

source/data-formats/extended-json.txt

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,57 @@ list of dictionaries by using the ``loads()`` method:
178178
{'bin': Binary(b'\x01\x02\x03\x04', 128)}
179179
]
180180

181+
.. _pymongo-extended-json-binary-values:
182+
183+
Reading Binary Values in Python 2
184+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185+
186+
In Python 3, the driver decodes JSON binary values with subtype 0 to instances of the
187+
``bytes`` class. In Python 2, the driver decodes these values to instances of the ``Binary``
188+
class with subtype 0.
189+
190+
The following code examples show how {+driver-short+} decodes JSON binary instances with
191+
subtype 0. Select the :guilabel:`Python 2` or :guilabel:`Python 3` tab to view the
192+
corresponding code.
193+
194+
.. tabs::
195+
196+
.. tab:: Python 2
197+
:tabid: python2
198+
199+
.. io-code-block::
200+
:copyable: true
201+
202+
.. input::
203+
:language: python
204+
205+
from bson.json_util import loads
206+
207+
doc = loads('{"b": {"$binary': b'this is a byte string'})
208+
print(doc)
209+
210+
.. output::
211+
212+
{u'b': Binary('this is a byte string', 0)}
213+
214+
.. tab:: Python 3
215+
:tabid: python3
216+
217+
.. io-code-block::
218+
:copyable: true
219+
220+
.. input::
221+
:language: python
222+
223+
from bson.json_util import loads
224+
225+
doc = loads('{"b": {"$binary': b'this is a byte string'})
226+
print(doc)
227+
228+
.. output::
229+
230+
{'b': b'this is a byte string'}
231+
181232
Write Extended JSON
182233
-------------------
183234

@@ -273,10 +324,30 @@ The following example shows how to output Extended JSON in the Canonical format:
273324
Additional Information
274325
----------------------
275326

327+
The resources in the following sections provide more information about working
328+
with Extended JSON.
329+
330+
API Documentation
331+
~~~~~~~~~~~~~~~~~
332+
276333
For more information about the methods and types in ``bson.json_util``, see the following
277334
API documentation:
278335

279336
- `loads() <{+api-root+}bson/json_util.html#bson.json_util.loads>`__
280337
- `dumps() <{+api-root+}bson/json_util.html#bson.json_util.dumps>`__
281338
- `CANONICAL_JSON_OPTIONS <{+api-root+}bson/json_util.html#bson.json_util.CANONICAL_JSON_OPTIONS>`__
282-
- `LEGACY_JSON_OPTIONS <{+api-root+}bson/json_util.html#bson.json_util.LEGACY_JSON_OPTIONS>`__
339+
- `LEGACY_JSON_OPTIONS <{+api-root+}bson/json_util.html#bson.json_util.LEGACY_JSON_OPTIONS>`__
340+
341+
Other Packages
342+
~~~~~~~~~~~~~~
343+
344+
`python-bsonjs <https://pypi.python.org/pypi/python-bsonjs>`__ is another package,
345+
built on top of `libbson <https://github.com/mongodb/libbson>`__,
346+
that can convert BSON to Extended JSON. The ``python-bsonjs`` package doesn't
347+
depend on {+driver-short+} and might offer a performance improvement over
348+
``json_util`` in certain cases.
349+
350+
.. tip:: Use the RawBSONDocument Type
351+
352+
``python-bsonjs`` works best with {+driver-short+} when converting from the
353+
``RawBSONDocument`` type.

0 commit comments

Comments
 (0)