I’m trying to find entries where the title field contains any item of an array.
Here is the relevant part of my schema:
const blogSchema = mongoose.Schema({
title: {
type: String,
required: true,
},
For example,
blogs = [
{title: "Lady swimming in the middle of an ocean"},
{title: "Waterfall on cliffside"}]
myArray = ["middle", "pillow"]
I want the find call to return the first entry
I’ve tried converting the array to a string using .join('')
and using a RegExp
Blog.find(title: new RegExp(myArray.join(''), 'i')
but this doesn’t return any entries, am I doing something wrong with the RegExp or is there a way to do this directly from the array without converting it to a string?