ClientEncryption.encryptExpression(keyId, expression, encOptions)ClientEncryption.encryptExpressionencrypts an MQL expression to query a range index, using the queried field'skeyIdand the query type and algorithm from theencOptionsdocument. It returns the encrypted result of the query.Returns: The encrypted result of the query as a
binary dataobject with subtype 6.
Compatibility
This command is available in deployments hosted in the following environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Syntax
clientEncryption = db.getMongo().getClientEncryption() clientEncryption.encryptExpression( keyId, expression, encOptions )
Parameter | Type | Description |
|---|---|---|
|
| The data encryption key for the field queried in the expression. The UUID is a BSON
|
| document | |
| document | A document with the fields:
|
Behavior
The mongosh client-side field level and queryable
encryption methods require a database connection configured for
client-side encryption. If the current database connection was not
initiated with client-side field level encryption enabled, either:
Use the
Mongo()constructor from themongoshto establish a connection with the required client-side field level encryption options. TheMongo()method supports the following Key Management Service (KMS) providers for Customer Master Key (CMK) management:
or
Use the
mongoshcommand line options to establish a connection with the required options. The command line options only support the Amazon Web Services KMS provider for CMK management.
Examples
clientEncryption.encryptExpression( UUID("64e2d87d-f168-493c-bbdf-a394535a2cb9"), { $and: [{ val: { $gt: Int32('100') } }, { val: { $lt: Int32('150') } }] }, { algorithm: 'range', queryType: 'range', rangeOptions: { min: Int32('0'), max: Int32('200') }, contentionFactor: 8 })
If successful, ClientEncryption.encryptExpression returns the encrypted
query result.
Learn More
For complete documentation on initiating MongoDB connections with
Client-Side Field Level Encryption or Queryable Encryption enabled, see Mongo().