Database Manual / Reference / Query Language / Expressions

$encStrNormalizedEq (encrypted aggregation operator)(加密聚合运算符)

Queryable Encryption equality and range queries are fully supported in production. Prefix, suffix, and substring queries are only available in public preview in MongoDB 8.2. Do not enable these query types in production. GA functionality of prefix, suffix and substring query types will be incompatible with the preview feature.可查询的加密相等性和范围查询在生产环境中得到了完全支持。前缀、后缀和子字符串查询仅在MongoDB 8.2的公共预览中可用。不要在生产环境中启用这些查询类型。前缀、后缀和子字符串查询类型的GA功能将与预览功能不兼容。To learn more, see Supported Query Types.要了解更多信息,请参阅支持的查询类型

Definition定义

New in version 8.2.在版本8.2中新增。

Note

The $encStrNormalizedEq aggregation operator is only for encrypted fields in collections with Queryable Encryption enabled. For unencrypted fields, use Text Search operators to match substrings.$encStrNormalizedEq聚合运算符仅适用于启用了可查询加密的集合中的加密字段。对于未加密的字段,使用文本搜索运算符匹配子字符串。

$encStrNormalizedEq

Returns true if a normalized string value matches the normalized string version of the specified string. 如果规范化字符串值与指定字符串的规范化字符串版本匹配,则返回trueThe queried field must have substring queries enabled, and the length of the query string must be between the configured minimum and maximum number of characters, inclusive.查询字段必须启用子字符串查询,查询字符串的长度必须介于配置的最小和最大字符数之间(包括最小和最大两个字符数)。

Note

This operator must operate on a text search index.此运算符必须对文本搜索索引进行操作。

The $encStrNormalizedEq expression has the following operator expression syntax:$encStrNormalizedEq表达式具有以下运算符表达式语法

{ $encStrNormalizedEq: { input: ’$fieldname’, string<target search key> } }

Behavior行为

  • Case sensitivity and diacritical mark sensitivity are determined by the configuration of the associated text search index.大小写敏感性和变音标记敏感性由相关文本搜索索引的配置决定。
  • Searches match whitespace characters.搜索匹配空白字符。
  • Line breaks aren't considered when matching.匹配时不考虑换行。
  • Tokenization delimiters aren't supported.不支持标记化分隔符。

Example示例

Consider the character é, which can be represented two ways:考虑字符é,它可以用两种方式表示:

  • One code point, U+00E9 (Latin small letter E with acute)一个代码点,U+00E9(拉丁文小写字母E,带锐角)
  • Two code points, U+0065 (Latin small letter E) followed by U+0301 (combining acute accent)两个代码点,U+0065(拉丁文小写字母E),后跟U+0301(结合重音)

When comparing these two different representations of the name Béatrice:当比较Béatrice名称的这两种不同表示时:

  • Using $eq evaluates to false, because the binary representations are different.使用$eq的结果为false,因为二进制表示不同。
  • Using $encStrNormalizedEq evaluates to true, regardless of the diacriticSensitive setting, because the operator normalizes both strings prior to comparing them.使用$encStrNormalizedEq的计算结果为true,而不管diacriticSensitive(变音符号敏感)设置如何,因为运算符在比较这两个字符串之前会对它们进行标准化。

In mongosh:

db.collection('MyCollection').aggregate([
{
$match: {
$expr: {
$encStrNormalizedEq: {
input: '$employeeLastName',
string: 'Béatrice'
}
}
}
}
])