If I have an array of different substring search parameters, such as:
const subStrings = ["foo", "bar", "baz", "whatever"];
I need to retrieve all the documents in which a string field contains at least one of the listed substrings.
For example, with a schema like this:
const sampleSchema = new mongoose.Schema({
fieldOne: {
type: String,
...
}
});
const Sample = mongoose.model('Sample', sampleSchema);
There is an approach I saw in other inquiries:
Sample.find ({
fieldOne: { $regex: substrings, $options: 'i' }
})
However, it seems that this method only works if the variable substrings
is a single string, not an array of strings.
Is there a way to modify the regex operation for this scenario, or is there another effective solution?