Database Manual / Reference / Query Language / Expressions

$encStrContains (encrypted aggregation operator)

Definition

New in version 8.2.

Note

The $encStrContains aggregation operator is only for encrypted fields in collections with Queryable Encryption enabled. For unencrypted fields, use Text Search operators to match substrings.

$encStrContains

Returns true if a subset of characters in a string value match the characters in the specified string. 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.

By default, strings must match case and diacritical marks.

  • Set caseSensitive to false in the encryption schema for case-insensitive matching.
  • Set diacriticSensitive to false in the encryption schema to disregard diacritic variations when matching.

The $encStrContains expression has the following operator expression syntax:

{ $encStrContains: <string> }

Behavior

  • Searches match whitespace characters.
  • Line breaks aren't considered when matching.
  • Tokenization delimiters aren't supported.

Example

In mongosh:

db.collection('MyCollection', function (err, collection) {
collection.aggregate([
$match: {
'employeeLastName': { $encStrContains: 'earso' }
}])

To match multiple fields:

db.collection('MyCollection', function (err, collection) {
collection.aggregate([
$match: {
'employeeLastName': { $encStrContains: 'earso' },
'employeeLastName': { $encStrEndsWith: 'wil' }
}])