I'm trying to create a dynamic filter that can be implemented using at least 3 letters. I've got a lot of fields which i will be filtering against.
As an example, If I am trying to find users by email, I want to be able to type "@gma" or at least "gma" and ideally, it should return an array of all users containing the specified filtering value. This should be the same when searching for properties like firstName and so on
My current solution only works if I provide a full value that matches what I already have in my database. e.g [email protected] for email or john for firstName. I want to be able to type jo for the latter.
const regexPattern = new RegExp(["^", filterUsersByValue, "$"].join(""), "i");
const filteredU = UserModel.find({ [filterUsersBy]: regexPattern})