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.
$encStrContainsReturns
trueif 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
caseSensitivetofalsein the encryption schema for case-insensitive matching.Set
diacriticSensitivetofalsein the encryption schema to disregard diacritic variations when matching.
The
$encStrContainsexpression 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' } }])