Skip to content

Commit 964d71c

Browse files
committed
Polishing.
Refine aspects of manual vs. derived collection setup. See #5016
1 parent ceb5360 commit 964d71c

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/main/antora/modules/ROOT/pages/mongodb/mongo-encryption.adoc

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,26 @@ The configuration for QE via Spring Data uses the same building blocks (a xref:m
135135

136136
You can configure Queryable Encryption either manually or in a derived way:
137137

138-
- Manual setup gives you full control over how encrypted fields are declared and how collections are created. It's useful when you need to explicitly manage data keys, encryption algorithms, and field mappings.
139-
- Derived setup relies on annotations in your domain model and automatically generates the required encrypted field configuration from it. This is simpler and recommended for typical Spring applications where your data model is already annotated.
138+
**Manual setup**
139+
140+
Manual setup gives you full control over how encrypted fields are declared and how collections are created.
141+
It's useful when you need to explicitly manage data keys, encryption algorithms, and field mappings.
142+
143+
** ✅ Full control over encryption configuration
144+
** ✅ Explicitly manage data keys and algorithms
145+
** ✅ Allows for complex encryption scenarios
146+
** ✅ Explicit configuration avoids the risk of surprises (e.g. missing configuration because of improper annotations or class-path scanning)
147+
** ⚠️ An Explicit Field Configuration can diverge from the domain model and you must keep it in sync with the domain model
148+
149+
**Derived setup*
150+
151+
Derived setup relies on annotations in your domain model and automatically generates the required encrypted field configuration from it.
152+
This is simpler and recommended for typical Spring applications where your data model is already annotated.
153+
154+
** ✅ Domain model-driven configuration
155+
** ✅ Easy to set up and maintain
156+
** ⚠️ Might not cover all complex scenarios
157+
** ⚠️ Risk of surprises (e.g. missing configuration for documents based on subtypes because of improper annotations or class-path scanning)
140158

141159
[tabs]
142160
======
@@ -170,23 +188,23 @@ Derived Collection Setup::
170188
----
171189
class Patient {
172190
173-
@Id String id; <1>
191+
@Id String id; <1>
174192
175-
Address address; <1>
193+
Address address; <1>
176194
177195
@Encrypted(algorithm = "Unindexed")
178-
String pin; <2>
196+
String pin; <2>
179197
180198
@Encrypted(algorithm = "Indexed")
181199
@Queryable(queryType = "equality", contentionFactor = 0)
182-
String ssn; <3>
200+
String ssn; <3>
183201
184202
@RangeEncrypted(contentionFactor = 8, rangeOptions = "{ 'min' : 0, 'max' : 150 }")
185-
Integer age; <4>
203+
Integer age; <4>
186204
187205
@RangeEncrypted(contentionFactor = 0L,
188206
rangeOptions = "{\"min\": {\"$numberDouble\": \"0.3\"}, \"max\": {\"$numberDouble\": \"2.5\"}, \"precision\": 2 }")
189-
double height; <5>
207+
double height; <5>
190208
}
191209
192210
MongoJsonSchema patientSchema = MongoJsonSchemaCreator.create(mappingContext)
@@ -202,11 +220,13 @@ template.execute(db -> clientEncryption.createEncryptedCollection(db, template.g
202220
.encryptedFields(encryptedFields), new CreateEncryptedCollectionParams("local"))); <1>
203221
204222
----
205-
<1> id and address are not encrypted and can be queried normally.
206-
<2> pin is encrypted but does not support queries.
207-
<3> ssn is encrypted and allows equality queries.
208-
<4> age is encrypted and allows range queries between 0 and 150.
209-
<5> height is encrypted and allows range queries between 0.3 and 2.5.
223+
224+
<1> `id` and `address` are not encrypted.
225+
Those fields can be queried normally.
226+
<2> `pin` is encrypted but does not support queries.
227+
<3> `ssn` is encrypted and allows equality queries.
228+
<4> `age` is encrypted and allows range queries between `0` and `150`.
229+
<5> `height` is encrypted and allows range queries between `0.3` and `2.5`.
210230

211231
The `Queryable` annotation allows to define allowed query types for encrypted fields.
212232
`@RangeEncrypted` is a combination of `@Encrypted` and `@Queryable` for fields allowing `range` queries.
@@ -268,7 +288,7 @@ MongoDB Collection Info::
268288
- Additional options for eg. `min` and `max` need to match the actual field type. Make sure to use `$numberLong` etc. to ensure target types when parsing bson String.
269289
- Queryable Encryption will an extra field `__safeContent__` to each of your documents.
270290
Unless explicitly excluded the field will be loaded into memory when retrieving results.
271-
- For a complete example, see Github project:
291+
- For a complete example, see:
272292
https://github.com/mongodb-developer/spring-data-queryable-encryption[spring-data-queryable-encryption]
273293
====
274294

0 commit comments

Comments
 (0)