Database Manual / Reference / Query Language / Expressions

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

$encStrEndsWith

Returns true if the last characters of a string value match the characters in the specified string. The queried field must have suffix queries enabled, and the length of the query string must be between the configured minimum and maximum number of characters, inclusive.如果字符串值的最后一个字符与指定字符串中的字符匹配,则返回true。查询字段必须启用后缀查询,查询字符串的长度必须介于配置的最小和最大字符数之间(包括最小和最大值)。

By default, strings must match case and diacritical marks.默认情况下,字符串必须匹配大小写和变音符号。

  • Set caseSensitive to false in the encryption schema for case-insensitive matching.在加密架构中将caseSensitive设置为false,以进行不区分大小写的匹配。
  • Set diacriticSensitive to false in the encryption schema to disregard diacritic variations when matching.在加密架构中将diacriticSensitive设置为false,以便在匹配时忽略变音符号变化。

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

{ $encStrEndsWith: { input: ’$fieldname’, suffix<target search key> } }

Behavior行为

  • Searches match whitespace characters.搜索匹配空白字符。
  • Line breaks aren't considered when matching.匹配时不考虑换行。
  • Tokenization delimiters aren't supported.不支持标记化分隔符。

Example示例

In mongosh:mongosh中:

db.collection('MyCollection').aggregate([
{
$match: {
$expr: {
$encStrEndsWith: {
input: '$employeeFirstName',
suffix: 'son'
}
}
}
}
])