@@ -5,8 +5,8 @@ Queryable Encryption
55.. versionadded :: 5.2.3
66
77Once you have successfully set up MongoDB Queryable Encryption as described in
8- :doc: `the installation guide < /howto/queryable-encryption > `, you can start
9- using encrypted fields in your Django models.
8+ :doc: `/howto/queryable-encryption `, you can start using encrypted fields in
9+ your Django models.
1010
1111Encrypted fields
1212================
@@ -59,6 +59,8 @@ Here are models based on the `Python Queryable Encryption Tutorial`_::
5959Migrations
6060----------
6161
62+ # TODO: this is coupled to the howto
63+
6264Once you have defined your models, create migrations with:
6365
6466.. code-block :: console
@@ -76,9 +78,14 @@ model data. The fields will automatically handle encryption and decryption,
7678ensuring that :ref: `sensitive data is stored securely in the database
7779<manual:qe-features-encryption-at-rest>`.
7880
81+ # TODO: once encrypted models are migrated, encrypted fields cannot be added or
82+ modified.
83+
7984Routers
8085-------
8186
87+ # TODO: this is redundant with the howto.
88+
8289The example above requires a :ref: `database router
8390<qe-configuring-database-routers-setting>` to direct operations on models with
8491encrypted fields to the appropriate database. It also requires the use of a
@@ -96,16 +103,15 @@ Querying encrypted fields
96103
97104In order to query encrypted fields, you must define the queryable encryption
98105query type in the model field definition. For example, if you want to query the
99- ``ssn `` field for equality, you can define it as follows ::
106+ ``ssn `` field for equality, you can add the `` queries `` argument ::
100107
101108 class PatientRecord(EmbeddedModel):
102109 ssn = EncryptedCharField(max_length=11, queries={"queryType": "equality"})
103- billing = EncryptedEmbeddedModelField("Billing")
104- bill_amount = models.DecimalField(max_digits=10, decimal_places=2)
105110
106- Then you can perform a query like this:
111+ Then you can perform a equality query just like you would on a non-encrypted
112+ field:
107113
108- .. code-block :: console
114+ .. code-block :: pycon
109115
110116 >>> patient = Patient.objects.get(patient_record__ssn="123-45-6789")
111117 >>> patient.name
@@ -116,13 +122,13 @@ Then you can perform a query like this:
116122Available query types
117123~~~~~~~~~~~~~~~~~~~~~
118124
119- The ``queries `` option should be a dictionary that specifies the type of queries
120- that can be performed on the field. Of the :ref: ` available query types
121- <manual:qe-fundamentals-encrypt-query>` Django MongoDB Backend currently
122- supports:
125+ The ``queries `` option should be a dictionary that specifies the type of
126+ queries that can be performed on the field, as well as any query options. The
127+ :ref: ` available query types <manual:qe-fundamentals-encrypt-query >` depend on
128+ your version of MongoDB.
123129
124- - ``equality ``
125- - ``range ``
130+ For example, in MongoDB 8.0, the supported types are ``equality `` and
131+ ``range ``.
126132
127133.. admonition :: Query types vs. Django lookups
128134
@@ -131,10 +137,41 @@ supports:
131137 perform comparisons on encrypted fields, while Django's range lookups are
132138 used for filtering based on a range of values.
133139
134- QuerySet limitations
135- ~~~~~~~~~~~~~~~~~~~~
140+ `` QuerySet `` limitations
141+ ~~~~~~~~~~~~~~~~~~~~~~~~
136142
137143In addition to :ref: `Django MongoDB Backend's QuerySet limitations
138- <known-issues-limitations-querying>`,
139-
140- .. TODO
144+ <known-issues-limitations-querying>`, some ``QuerySet `` methods aren't
145+ supported on encrypted fields. Each unsupported method is followed by a sample
146+ error message from the database. Depending on the exact query, error messages
147+ may vary.
148+
149+ - :meth: `~django.db.models.query.QuerySet.order_by `: Cannot add an encrypted
150+ field as a prefix of another encrypted field.
151+ - :meth: `~django.db.models.query.QuerySet.alias `,
152+ :meth: `~django.db.models.query.QuerySet.annotate `,
153+ :meth: `~django.db.models.query.QuerySet.distinct `: Cannot group on field
154+ '_id.value' which is encrypted with the random algorithm or whose encryption
155+ properties are not known until runtime.
156+ - :meth: `~django.db.models.query.QuerySet.dates `,
157+ :meth: `~django.db.models.query.QuerySet.datetimes `: If the value type is a
158+ date, the type of the index must also be date (and vice versa).
159+ - :meth: `~django.db.models.query.QuerySet.in_bulk `: Encrypted fields can't have
160+ unique constraints.
161+
162+ # TODO: add details about joined queries after
163+ https://github.com/mongodb/django-mongodb-backend/pull/443 is finalized.
164+
165+ There are also several ``QuerySet `` methods that aren't permitted on any models
166+ (regardless of whether or not they have encrypted fields) that use a database
167+ connection with Automatic Encryption. Each unsupported method is followed by a
168+ sample error message from the database.
169+
170+ - :meth: `~django.db.models.query.QuerySet.update `: Multi-document updates are
171+ not allowed with Queryable Encryption.
172+ - :meth: `~django.db.models.query.QuerySet.aggregate `,
173+ :meth: `~django.db.models.query.QuerySet.count `: Aggregation stage
174+ $internalFacetTeeConsumer is not allowed or supported with automatic
175+ encryption.
176+ - :meth: `~django.db.models.query.QuerySet.union `: Aggregation stage $unionWith
177+ is not allowed or supported with automatic encryption.
0 commit comments