Hi,
I’m making an application for therapists, where each therapist has its own patients.
The therapist should be able to search for the firstName and/or lastName.
I store and search the names “normalized” and “inverted”.
“Jérôme Müller” becomes “jerome muller” and “muller jerome”
therapistSchema = {
id: "abc123",
// more...
}
patientScheam = {
firstName: "Jérôme",
lastName: "Müller",
owner: "abc123",
search: [
// (the search array is indexed)
"abc123_jerome muller",
"abc123_muller jerome"
],
// more...
}
I query it with Patien.find( { search: /^abc123_SEARCH/ } )
where SEARCH is the string the therapists is searing for. It queries efficient using the search_1
index.
I’m very happy with it but I would love to know if someone else has an ever better solution or if there is a “native MongoDB” way to get the same result?
Thanks!