Skip to content

Commit 5752f45

Browse files
DOCSP-47173 - Remove FAQs (#175)
Co-authored-by: Jordan Smith <[email protected]> (cherry picked from commit 39799a5) (cherry picked from commit 4281bb3)
1 parent 32a272d commit 5752f45

File tree

13 files changed

+381
-456
lines changed

13 files changed

+381
-456
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: 125 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,136 @@ instance on port ``27017`` of ``localhost``:
9797
uri = "mongodb://localhost:27017/"
9898
client = MongoClient(uri)
9999

100-
.. tip:: Reusing Your Client
100+
The following table describes the positional parameters that the ``MongoClient()``
101+
constructor accepts. All parameters are optional.
101102

102-
Because each ``MongoClient`` object represents a pool of connections to the
103-
database, most applications require only a single instance of
104-
``MongoClient``, even across multiple requests. However, if you fork
105-
a process, the child process *does* need its own ``MongoClient`` object.
106-
To learn more, see the :ref:`FAQ <pymongo-faq>` page.
103+
.. list-table::
104+
:widths: 20 80
105+
:header-rows: 1
106+
107+
* - Parameter
108+
- Description
109+
110+
* - ``host``
111+
- The hostname, IP address, or Unix domain socket path of the MongoDB deployment.
112+
If your application connects to a replica set or sharded cluster, you can specify
113+
multiple hostnames or IP addresses in a Python list.
114+
115+
If you pass a literal IPv6 address, you must enclose the address in square brackets
116+
(``[ ]``). For example, pass the value ``[::1]`` to connect to localhost.
117+
118+
{+driver-short+} doesn't support :wikipedia:`multihomed <Multihoming>` and
119+
:wikipedia:`round-robin DNS <Round-robin_DNS>` addresses.
120+
121+
**Data type:** ``Union[str, Sequence[str]]``
122+
**Default value:** ``"localhost"``
123+
124+
* - ``port``
125+
- The port number {+mdb-server+} is running on.
126+
127+
You can include the port number in the ``host`` argument
128+
instead of using this parameter.
129+
130+
**Data type:** ``int``
131+
**Default value:** ``27017``
132+
133+
* - ``document_class``
134+
- The default class that the client uses to decode BSON documents returned by queries.
135+
This parameter supports the ``bson.raw_bson.RawBSONDocument`` type, as well as
136+
subclasses of the ``collections.abc.Mapping`` type, such as ``bson.son.SON``.
137+
138+
If you specify ``bson.son.SON`` as the document class, you must also specify types
139+
for the key and value.
140+
141+
**Data type:** ``Type[_DocumentType]``
142+
143+
* - ``tz_aware``
144+
- If this parameter is ``True``, the client treats ``datetime`` values as aware.
145+
Otherwise, it treats them as naive.
146+
147+
For more information about aware and naive ``datetime`` values, see
148+
`datetime <https://docs.python.org/3/library/datetime.html>`__ in the Python
149+
documentation.
150+
151+
**Data type:** ``bool``
152+
153+
* - ``connect``
154+
- If this parameter is ``True``, the client begins connecting to MongoDB
155+
in the background immediately after you create it. If this parameter is ``False``,
156+
the client connects to MongoDB when it performs the first database operation.
157+
158+
If your application is running in a
159+
:wikipedia:`function-as-a-service (FaaS) <Function_as_a_service>`
160+
environment, the default value is ``False``. Otherwise, the default value is ``True``.
161+
162+
**Data type:** ``bool``
163+
164+
* - ``type_registry``
165+
- An instance of the ``TypeRegistry`` class to enable encoding and decoding of
166+
custom types. For more information about encoding and decoding custom types,
167+
see :ref:`pymongo-custom-types`.
168+
169+
**Data type:** `TypeRegistry <{+api-root+}bson/codec_options.html#bson.codec_options.TypeRegistry>`__
170+
171+
Concurrent Execution
172+
--------------------
173+
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.
107225

108226
API Documentation
109227
-----------------
110228

111229
To learn more about creating a ``MongoClient`` object in {+driver-short+},
112230
see the following API documentation:
113231

114-
- `MongoClient <{+api-root+}pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__
232+
- `MongoClient <{+api-root+}pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__

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)