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/"
15
15
mdb-server = " MongoDB Server"
16
16
django-version = " 5.0"
17
17
django-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
47
47
MongoDB-specific method, set your model's ``objects`` field to a custom
48
48
manager called ``MongoManager``.
49
49
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
+
50
53
Sample Data
51
54
~~~~~~~~~~~
52
55
@@ -293,6 +296,33 @@ code performs the following actions:
293
296
Theater ID: 814
294
297
Theater ID: 323
295
298
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
+
296
326
Additional Information
297
327
----------------------
298
328
You can’t perform that action at this time.
0 commit comments