@@ -21,6 +21,9 @@ queries on certain encrypted fields. To use encrypted fields in your models,
2121import the necessary field types from ``django_mongodb_backend.models `` and
2222define your models as usual.
2323
24+ Here's the `Python Queryable Encryption Tutorial `_ example implemented in
25+ Django:
26+
2427.. code-block :: python
2528
2629 # myapp/models.py
@@ -94,8 +97,10 @@ query type in the model field definition. For example, if you want to query the
9497 billing = EncryptedEmbeddedModelField(" Billing" )
9598 bill_amount = models.DecimalField(max_digits = 10 , decimal_places = 2 )
9699
97- Query types
98- ~~~~~~~~~~~
100+ .. _qe-available-query-types :
101+
102+ Available query types
103+ ~~~~~~~~~~~~~~~~~~~~~
99104
100105The ``queries `` option should be a dictionary that specifies the type of queries
101106that can be performed on the field. The :ref: `available query types
@@ -116,30 +121,12 @@ For example, to find a patient by their SSN, you can do the following::
116121 >>> patient.name
117122 'Bob'
118123
119-
120124QuerySet limitations
121125~~~~~~~~~~~~~~~~~~~~
122126
123- When using Django QuerySets with MongoDB Queryable Encryption, it’s important to
124- understand that many typical ORM features are restricted because the database
125- only sees encrypted ciphertext, not plaintext. This means that only certain
126- query types are supported, and a lot of filtering, sorting, and aggregating must
127- be done client-side after decryption. Key limitations include:
128-
129- - **Equality only filtering ** – You can filter encrypted fields using exact
130- matches, but operators like contains, startswith, regex, or unsupported range
131- lookups will not work.
132- - **No server-side sorting ** – .order_by() on encrypted fields won’t produce
133- meaningful results; sorting needs to happen after decryption in Python.
134- - **No server-side aggregation ** – Functions like annotate() or aggregate()
135- won’t operate on encrypted fields; you must aggregate locally after fetching
136- data.
137- - **Index constraints ** – Queries are only possible on encrypted fields that
138- have a configured queryable encryption index and keys available on the client.
139- - **No joins on encrypted fields ** – Filtering across relationships using
140- encrypted foreign keys is unsupported because matching must happen
141- client-side.
142-
143- In short, when working with Queryable Encryption, design your queries to use
144- exact matches only on encrypted fields, and plan to handle any sorting or
145- aggregation after results are decrypted in your application code.
127+ In addition to :ref: `Django MongoDB Backend's QuerySet limitations
128+ <known-issues-limitations-querying>`,
129+
130+ .. TODO
131+
132+ .. _Python Queryable Encryption Tutorial : https://github.com/mongodb/docs/tree/main/content/manual/manual/source/includes/qe-tutorials/python
0 commit comments