Definition
New in version 8.2.
Note
The $encStrStartsWith
aggregation operator is only for encrypted fields in
collections with Queryable Encryption enabled. For
unencrypted fields, use Text Search operators to match
substrings.
$encStrStartsWith
Returns
true
if the first characters of a string value match the specified string. The queried field must have prefix 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
tofalse
in the encryption schema for case-insensitive matching.Set
diacriticSensitive
tofalse
in the encryption schema to disregard diacritic variations when matching.
The
$encStrStartsWith
expression has the following operator expression syntax:{ $encStrStartsWith: <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: { 'employeeFirstName': { $encStrStartsWith: 'Sam' } }])