对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

ClientEncryption.encryptExpression()(mongosh方法)

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
clientEncryption = db.getMongo().getClientEncryption()
clientEncryption.encryptExpression(
keyId,
expression,
encOptions
)
Parameter
类型
说明

keyId

UUID

表达式中查询的字段的数据加密密钥。

The UUID is a BSON binary data object with subtype 4 that identifies a specific data encryption key. If the data encryption key does not exist in the key vault configured for the database connection, encryptExpression() returns an error. See Key Vault Collections for more information on key vaults and data encryption keys.

expression

文档

要加密的范围查询表达式,可为以下形式之一:

  • 采用以下形式的$match表达式:{$and: [{<field>: {$gt: <value1>}}, {<field>: {$lt: <value2> }}]}

  • 采用以下形式的 aggregate 表达式:{$and: [{$gt: [<fieldpath>, <value1>]}, {$lt: [<fieldpath>, <value2>]}]}

表达式还可以使用 $lte 或 $gte

encOptions

文档

一个包含以下字段的文档:

  • algorithm:用于加密 expression 的加密算法。必须设立为 "range"。

  • queryType:查询类型。必须设立为 "range"。

  • rangeOptions:具有范围查询设置的文档。值必须与集合的加密模式中的值匹配。

    • min、max:与字段的BSON类型匹配的最小值和最大值。

    • precision: MongoDB在查询 double 和 decimal128 字段时考虑的有效位数。

    • sparsity:影响MongoDB对范围值进行索引的彻底程度。

    • trimFactor:控制并发插入和更新的吞吐量。

  • contentionFactor:与表达式中字段值的频率有关。有关详细信息,请参阅争用。

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:

or

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()。

给本页内容打分