Skip to content

DOCSP-46688: Add collection configuration sections #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions source/databases-collections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Access a Database

Access a database by using dictionary-style access on your ``MongoClient`` instance.

The following example accesses a database named "test_database":
The following example accesses a database named ``test_database``:

.. code-block:: python

Expand All @@ -50,7 +50,7 @@ Access a Collection

Access a collection by using dictionary-style access on an instance of your database.

The following example accesses a collection named "test_collection":
The following example accesses a collection named ``test_collection``:

.. code-block:: python
:emphasize-lines: 2
Expand All @@ -70,7 +70,7 @@ Create a Collection
Use the ``create_collection()`` method to explicitly create a collection in a
MongoDB database.

The following example creates a collection called ``"example_collection"``:
The following example creates a collection called ``example_collection``:

.. code-block:: python
:emphasize-lines: 2
Expand All @@ -83,6 +83,36 @@ validation rules, by passing them in as keyword arguments. For a full list of
optional parameters, see the `create_collection() API documentation
<{+api-root+}pymongo/database.html#pymongo.database.Database.create_collection>`__.

Time Series Collection
~~~~~~~~~~~~~~~~~~~~~~

Time series collections efficiently store sequences of measurements over a period of time.
The following example creates a time series collection called ``example_ts_collection``
in which the documents' time field is called ``timestamp``:

.. code-block:: python

database = client["test_database"]
database.create_collection("example_ts_collection", timeseries={"timeField": "timestamp"})

For more information about using time series data with {+driver-short+}, see the
:ref:`pymongo-time-series` guide.

Capped Collection
~~~~~~~~~~~~~~~~~

You can create a capped collection that cannot grow beyond a specified memory size or
document count. The following example creates a capped collection called
``example_capped_collection`` that has a maximum size of 1000 bytes:

.. code-block:: python

database = client["test_database"]
database.create_collection("example_capped_collection", capped=True, size=1000)

To learn more about capped collections, see :manual:`Capped Collections </core/capped-collections/>`
in the {+mdb-server+} manual.

Get a List of Collections
-------------------------

Expand Down
Loading