File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -15,3 +15,4 @@ api = "https://django-mongodb.readthedocs.io/en/latest/"
1515mdb-server = " MongoDB Server"
1616django-version = " 5.0"
1717django-docs = " https://docs.djangoproject.com/en/{+django-version+}"
18+ pymongo-docs = " https://www.mongodb.com/docs/languages/python/pymongo-driver/current/"
Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ Django adds a ``Manager`` named ``objects`` to every model class. This default
4747MongoDB-specific method, set your model's ``objects`` field to a custom
4848manager called ``MongoManager``.
4949
50+ As an alternative to the ``raw_aggregate()`` method, you can run queries directly
51+ on your ``MongoClient`` object for expanded access to your MongoDB data.
52+
5053Sample Data
5154~~~~~~~~~~~
5255
@@ -293,6 +296,33 @@ code performs the following actions:
293296 Theater ID: 814
294297 Theater ID: 323
295298
299+ .. _django-client-operations:
300+
301+ MongoClient Operations
302+ ----------------------
303+
304+ If you want to run database operations that neither the ``QuerySet`` API
305+ nor the ``raw_aggregate()`` method provide, you can operate on your
306+ ``MongoClient`` directly. When working with the ``MongoClient``, you can
307+ can access the PyMongo driver's database operations. Use the following
308+ syntax to expose the ``MongoClient``:
309+
310+ .. code-block::
311+ :language: python
312+
313+ from django.db import connections
314+
315+ client = connections["<DATABASES key>"].database.client
316+
317+ Replace the ``"<DATABASES key>"`` placeholder with the key in your
318+ ``DATABASES`` dictionary that corresponds to your target database. To
319+ use your default database, replace the placeholder with ``"default"``.
320+
321+ .. tip::
322+
323+ To learn how to use PyMongo to interact with MongoDB data,
324+ see the `PyMongo documentation. <{+pymongo-docs+}>`__
325+
296326Additional Information
297327----------------------
298328
You can’t perform that action at this time.
0 commit comments