I have a mongodb of recipes and I want to dynamically create a general search query resulting in:
{ $all: [/potato/i, /onion/i, /garlic/i, /chicken/i] }
Without quotation marks from a string like:
const str = 'potato onion garlic chicken'
I've attempted:
const arr = []
str.split(' ').forEach(element => {
arr.push(`/${element}/i`)
})
console.log(arr)
The problem is I end up with strings:
//[ '/potato/i', '/onion/i', '/garlic/i', '/chicken/i' ]
How do can I dynamically create this query without stringifying?