ClientEncryption.encryptExpression(keyId, expression, encOptions)ClientEncryption.encryptExpression加密 MQL 表达式 以查询范围索引,使用查询字段的keyId以及encOptions文档中的查询类型和算法。它返回查询的加密结果。返回: binary data作为具有子类型6 的 对象的加密查询结果。
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
clientEncryption = db.getMongo().getClientEncryption() clientEncryption.encryptExpression( keyId, expression, encOptions )
Parameter | 类型 | 说明 |
|---|---|---|
|
| 表达式中查询的字段的数据加密密钥。 The UUID is a BSON |
| 文档 | |
| 文档 | 一个包含以下字段的文档:
|
行为
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:
使用
mongosh中的Mongo()构造函数与所需的客户端字段级加密选项建立连接。Mongo()方法支持以下用于“客户主密钥”(KMS) 管理的“密钥管理服务”(CMK) 提供商:
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.
示例
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 })
如果成功,ClientEncryption.encryptExpression 将返回加密的查询结果。
了解详情
有关在启用客户端字段级加密或Queryable Encryption的情况下启动MongoDB连接的完整文档,请参阅 Mongo()。