Categories
JavaScript Answers

How to get all the values that contains part of a string using Node Mongoose find?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.