Encrypted fields¶
Added in version 5.2.3.
Django MongoDB Backend supports Queryable Encryption.
See Configuring Queryable Encryption for more information on how to use Queryable Encryption with Django MongoDB Backend.
See the Queryable Encryption topic guide for more information on developing applications with Queryable Encryption.
The following tables detailed which fields have encrypted counterparts. In all
cases, the encrypted field names are simply prefixed with Encrypted, e.g.
EncryptedCharField. They are importable from
django_mongodb_backend.fields.
Model Field |
Encrypted version available? |
|---|---|
Yes |
|
Yes |
|
Yes |
|
Yes |
|
Yes |
|
Yes |
|
Yes |
|
Yes |
|
Yes |
|
No: the use case for encrypting this field is unclear. |
|
No: the use case for encrypting this field is unclear. |
|
Yes |
|
No: the use case for encrypting this field is unclear. |
|
Yes |
|
No: |
|
Yes |
|
Yes |
|
Yes |
|
No: it requires a unique index which Queryable Encryption doesn’t support. |
|
Yes |
|
Yes |
|
Yes |
|
Yes |
|
Yes |
Model Field |
Encrypted version available? |
|---|---|
Yes |
|
Yes |
|
Yes |
|
Yes |
|
No: may be implemented in the future. |
|
No: may be implemented in the future. |
These fields don’t support the queries argument:
EncryptedArrayFieldEncryptedEmbeddedModelArrayFieldEncryptedEmbeddedModelField
Limitations¶
MongoDB imposes some restrictions on encrypted fields:
They cannot be indexed.
They cannot be part of a unique constraint.
They cannot be null.
EncryptedFieldMixin¶
- class EncryptedFieldMixin¶
Added in version 5.2.3.
A mixin that can be used to create custom encrypted fields with Queryable Encryption.
To create an encrypted field, inherit from
EncryptedFieldMixinand your custom field class:from django.db import models from django_mongodb_backend.fields import EncryptedFieldMixin from myapp.fields import MyField class MyEncryptedField(EncryptedFieldMixin, MyField): pass
You can then use your custom encrypted field in a model, specifying the desired query types:
class MyModel(models.Model): my_encrypted_field = MyEncryptedField( queries={"queryType": "equality"}, ) my_encrypted_field_too = MyEncryptedField( queries={"queryType": "range"}, )