Hi @Johannes_B,
Ok thank you for explaining in more detail. My solution was relevant for the first example when the full name is provided. This is since text searches are based on words or delimited words. Therefore with a text index you cant search a partial expression.
I suggest exploring our Atlas search which comes to solve those problems on Atlas:
The original example was considering the following documents:
{ _id: ObjectID("5f2949ebbdee40880a3db0c0"),
name: { first: 'David', family: 'Christiansen' } }
{ _id: ObjectID("5f294e2bbdee40880a3db0c1"),
name: { first: 'David', family: 'Owen-Christiansen' } }
Where the following aggregation will find the needed document:
db.users.aggregate([{$match: {
$text :{ "$search" : "christiansen" }
}}, {$match: {
"name.family" : /^christiansen/i
}}])
[
name: { first: 'David', family: 'Christiansen' } } ]
This will utilize the text index.
Best regards
Pavel