Skip to content

feat(NODE-7059, NODE-7008): add support for text queries for QE string fields #4597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ declare global {
idmsMockServer?: true;
nodejs?: string;
predicate?: (test?: Mocha.Test) => true | string;
crypt_shared?: 'enabled' | 'disabled'
crypt_shared?: 'enabled' | 'disabled',
libmongocrypt?: string;
};

sessions?: {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"js-yaml": "^4.1.0",
"mocha": "^11.7.1",
"mocha-sinon": "^2.1.2",
"mongodb-client-encryption": "^6.4.0",
"mongodb-client-encryption": "^6.5.0",
"mongodb-legacy": "^6.1.3",
"nyc": "^15.1.0",
"prettier": "^3.5.3",
Expand Down Expand Up @@ -175,4 +175,4 @@
"moduleResolution": "node"
}
}
}
}
55 changes: 52 additions & 3 deletions src/client-side-encryption/client_encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ export class ClientEncryption {
expressionMode: boolean,
options: ClientEncryptionEncryptOptions
): Promise<Binary> {
const { algorithm, keyId, keyAltName, contentionFactor, queryType, rangeOptions } = options;
const { algorithm, keyId, keyAltName, contentionFactor, queryType, rangeOptions, textOptions } =
options;
const contextOptions: ExplicitEncryptionContextOptions = {
expressionMode,
algorithm
Expand Down Expand Up @@ -782,6 +783,10 @@ export class ClientEncryption {
contextOptions.rangeOptions = serialize(rangeOptions);
}

if (typeof textOptions === 'object') {
contextOptions.textOptions = serialize(textOptions);
}

const valueBuffer = serialize({ v: value });
const stateMachine = new StateMachine({
proxyOptions: this._proxyOptions,
Expand Down Expand Up @@ -812,7 +817,8 @@ export interface ClientEncryptionEncryptOptions {
| 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'
| 'Indexed'
| 'Unindexed'
| 'Range';
| 'Range'
| 'TextPreview';

/**
* The id of the Binary dataKey to use for encryption
Expand All @@ -830,10 +836,53 @@ export interface ClientEncryptionEncryptOptions {
/**
* The query type.
*/
queryType?: 'equality' | 'range';
queryType?: 'equality' | 'range' | 'prefixPreview' | 'suffixPreview' | 'substringPreview';

/** The index options for a Queryable Encryption field supporting "range" queries.*/
rangeOptions?: RangeOptions;

/**
* Options for a Queryable Encryption field supporting text queries. Only valid when `algorithm` is `TextPreview`.
*
* @experimental Public Technical Preview: `textPreview` is an experimental feature and may break at any time.
*/
textOptions?: TextQueryOptions;
}

/**
* Options for a Queryable Encryption field supporting text queries.
*
* @public
* @experimental Public Technical Preview: `textPreview` is an experimental feature and may break at any time.
*/
export interface TextQueryOptions {
/** Indicates that text indexes for this field are case sensitive */
caseSensitive: boolean;
/** Indicates that text indexes for this field are diacritic sensitive. */
diacriticSensitive: boolean;

prefix?: {
/** The maximum allowed query length. */
strMaxQueryLength: Int32 | number;
/** The minimum allowed query length. */
strMinQueryLength: Int32 | number;
};

suffix?: {
/** The maximum allowed query length. */
strMaxQueryLength: Int32 | number;
/** The minimum allowed query length. */
strMinQueryLength: Int32 | number;
};

substring?: {
/** The maximum allowed length to insert. */
strMaxLength: Int32 | number;
/** The maximum allowed query length. */
strMaxQueryLength: Int32 | number;
/** The minimum allowed query length. */
strMinQueryLength: Int32 | number;
};
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ export type {
DataKey,
GCPEncryptionKeyOptions,
KMIPEncryptionKeyOptions,
RangeOptions
RangeOptions,
TextQueryOptions
} from './client-side-encryption/client_encryption';
export {
MongoCryptAzureKMSRequestError,
Expand Down
Loading