To get all the values that contains part of a string using Node Mongoose find, we can search with a regex.
For instance, we write
Books.find({ authors: /Alex/i }, (err, docs) => {});
to call find
with an object that has authors
set to the regex with the pattern we’re looking for.
And we get the results from the docs
array.
We use the i
flag to search in a case insensitive manner.