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聚合运算符仅适用于启用了可查询加密的集合中的加密字段。对于未加密的字段,使用文本搜索运算符匹配子字符串。
$encStrNormalizedEqReturns如果规范化字符串值与指定字符串的规范化字符串版本匹配,则返回trueif a normalized string value matches the normalized string version of the specified string.true。The 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$encStrNormalizedEqexpression 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 byU+0301(combining acute accent)U+0065(拉丁文小写字母E),后跟U+0301(结合重音)
When comparing these two different representations of the name Béatrice:当比较Béatrice名称的这两种不同表示时:
Using使用$eqevaluates tofalse, because the binary representations are different.$eq的结果为false,因为二进制表示不同。Using使用$encStrNormalizedEqevaluates totrue, regardless of thediacriticSensitivesetting, 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'
}
}
}
}
])