Skip to content

Commit 25ebca1

Browse files
authored
DRIVERS-3213 add text search explicit encryption API and tests (#1824)
1 parent 48ce8ac commit 25ebca1

File tree

4 files changed

+447
-8
lines changed

4 files changed

+447
-8
lines changed

source/client-side-encryption/client-side-encryption.md

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ QEv1 and QEv2 are incompatible.
4848
MongoDB 8.0 dropped `queryType=rangePreview` and added `queryType=range`
4949
([SPM-3583](https://jira.mongodb.org/browse/SPM-3583)).
5050

51+
MongoDB 8.2 added unstable support for QE text queries ([SPM-2880](https://jira.mongodb.org/browse/SPM-2880))
52+
5153
## META
5254

5355
The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
@@ -1256,6 +1258,7 @@ class EncryptOpts {
12561258
contentionFactor: Optional<Int64>,
12571259
queryType: Optional<String>
12581260
rangeOpts: Optional<RangeOpts>
1261+
textOpts: Optional<TextOpts>
12591262
}
12601263

12611264
// RangeOpts specifies index options for a Queryable Encryption field supporting "range" queries.
@@ -1273,6 +1276,48 @@ class RangeOpts {
12731276
// precision determines the number of significant digits after the decimal point. May only be set for double or decimal128.
12741277
precision: Optional<Int32>
12751278
}
1279+
1280+
// TextOpts specifies options for a Queryable Encryption field supporting text queries.
1281+
// NOTE: TextOpts is currently unstable API and subject to backwards breaking changes.
1282+
class TextOpts {
1283+
// substring contains further options to support substring queries.
1284+
substring: Optional<SubstringOpts>,
1285+
// prefix contains further options to support prefix queries.
1286+
prefix: Optional<PrefixOpts>,
1287+
// suffix contains further options to support suffix queries.
1288+
suffix: Optional<SuffixOpts>,
1289+
// caseSensitive determines whether text indexes for this field are case sensitive.
1290+
caseSensitive: bool,
1291+
// diacriticSensitive determines whether text indexes for this field are diacritic sensitive.
1292+
diacriticSensitive: bool
1293+
}
1294+
1295+
// NOTE: SubstringOpts is currently unstable API and subject to backwards breaking changes.
1296+
class SubstringOpts {
1297+
// strMaxLength is the maximum allowed length to insert. Inserting longer strings will error.
1298+
strMaxLength: Int32,
1299+
// strMinQueryLength is the minimum allowed query length. Querying with a shorter string will error.
1300+
strMinQueryLength: Int32,
1301+
// strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error.
1302+
strMaxQueryLength: Int32,
1303+
}
1304+
1305+
// NOTE: PrefixOpts is currently unstable API and subject to backwards breaking changes.
1306+
class PrefixOpts {
1307+
// strMinQueryLength is the minimum allowed query length. Querying with a shorter string will error.
1308+
strMinQueryLength: Int32,
1309+
// strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error.
1310+
strMaxQueryLength: Int32,
1311+
}
1312+
1313+
// NOTE: SuffixOpts is currently unstable API and subject to backwards breaking changes.
1314+
class SuffixOpts {
1315+
// strMinQueryLength is the minimum allowed query length. Querying with a shorter string will error.
1316+
strMinQueryLength: Int32,
1317+
// strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error.
1318+
strMaxQueryLength: Int32,
1319+
}
1320+
12761321
```
12771322
12781323
Explicit encryption requires a key and algorithm. Keys are either identified by `_id` or by alternate name. Exactly one
@@ -1295,34 +1340,45 @@ One of the strings:
12951340
- "Indexed"
12961341
- "Unindexed"
12971342
- "Range"
1343+
- "TextPreview"
12981344
1299-
The result of explicit encryption with the "Indexed" or "Range" algorithm must be processed by the server to insert or
1300-
query. Drivers MUST document the following behavior:
1345+
The result of explicit encryption with the "Indexed", "Range", or "TextPreview" algorithm must be processed by the
1346+
server to insert or query. Drivers MUST document the following behavior:
13011347
1302-
> To insert or query with an "Indexed" or "Range" encrypted payload, use a `MongoClient` configured with
1348+
> To insert or query with an "Indexed", "Range", or "TextPreview" encrypted payload, use a `MongoClient` configured with
13031349
> `AutoEncryptionOpts`. `AutoEncryptionOpts.bypassQueryAnalysis` may be true. `AutoEncryptionOpts.bypassAutoEncryption`
1304-
> must be false.
1350+
> must be false. The "TextPreview" algorithm is in preview and should be used for experimental workloads only. These
1351+
> features are unstable and their security is not guaranteed until released as Generally Available (GA). The GA version
1352+
> of these features may not be backwards compatible with the preview version.
13051353
13061354
#### contentionFactor
13071355
1308-
contentionFactor may be used to tune performance. Only applies when algorithm is "Indexed" or "Range". libmongocrypt
1309-
returns an error if contentionFactor is set for a non-applicable algorithm.
1356+
contentionFactor may be used to tune performance. Only applies when algorithm is "Indexed", "Range", or "TextPreview".
1357+
libmongocrypt returns an error if contentionFactor is set for a non-applicable algorithm.
13101358
13111359
#### queryType
13121360
13131361
One of the strings:
13141362
13151363
- "equality"
13161364
- "range"
1365+
- "prefixPreview"
1366+
- "suffixPreview"
1367+
- "substringPreview"
13171368
1318-
queryType only applies when algorithm is "Indexed" or "Range". libmongocrypt returns an error if queryType is set for a
1319-
non-applicable queryType.
1369+
queryType only applies when algorithm is "Indexed", "Range", or "TextPreview". libmongocrypt returns an error if
1370+
queryType is set for a non-applicable algorithm.
13201371
13211372
#### rangeOpts
13221373
13231374
rangeOpts only applies when algorithm is "Range". libmongocrypt returns an error if rangeOpts is set for a
13241375
non-applicable algorithm.
13251376
1377+
#### textOpts
1378+
1379+
textOpts only applies when algorithm is "TextPreview". libmongocrypt returns an error if textOpts is set for a
1380+
non-applicable algorithm.
1381+
13261382
## User facing API: When Auto Encryption Fails
13271383
13281384
Auto encryption requires parsing the MongoDB query language client side (with the [mongocryptd](#mongocryptd) process or
@@ -2463,6 +2519,8 @@ explicit session parameter as described in the [Drivers Sessions Specification](
24632519

24642520
## Changelog
24652521

2522+
- 2025-08-06: Add `TextPreview` algorithm.
2523+
24662524
- 2024-02-19: Add custom options AWS credential provider.
24672525

24682526
- 2024-10-09: Add retry prose test.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedText",
11+
"bsonType": "string",
12+
"queries": [
13+
{
14+
"queryType": "prefixPreview",
15+
"strMinQueryLength": {
16+
"$numberInt": "2"
17+
},
18+
"strMaxQueryLength": {
19+
"$numberInt": "10"
20+
},
21+
"caseSensitive": true,
22+
"diacriticSensitive": true
23+
},
24+
{
25+
"queryType": "suffixPreview",
26+
"strMinQueryLength": {
27+
"$numberInt": "2"
28+
},
29+
"strMaxQueryLength": {
30+
"$numberInt": "10"
31+
},
32+
"caseSensitive": true,
33+
"diacriticSensitive": true
34+
}
35+
]
36+
}
37+
]
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedText",
11+
"bsonType": "string",
12+
"queries": [
13+
{
14+
"queryType": "substringPreview",
15+
"strMaxLength": {
16+
"$numberInt": "10"
17+
},
18+
"strMinQueryLength": {
19+
"$numberInt": "2"
20+
},
21+
"strMaxQueryLength": {
22+
"$numberInt": "10"
23+
},
24+
"caseSensitive": true,
25+
"diacriticSensitive": true
26+
}
27+
]
28+
}
29+
]
30+
}

0 commit comments

Comments
 (0)