Answer the question
In order to leave comments, you need to log in
How to search with regular expressions in mongoose?
OK. I have, for example:
const { searchText } = req.body;
And you need to execute
But use as in SQL - LIKE '% %'. It seems to have found how, like find({name: /Value/}), but it does not work. model.find({ name: searchText });
Answer the question
In order to leave comments, you need to log in
Search using regular expressions:
Works slowly, if there is an index on the field it will be faster, but only if it is the beginning of a word /^Value/
It is better to use a text index for searching
use: Text Index $text
find({name: {$regex: /Значение/}}),
createIndex( { name: "text" } )
find( { $text: { $search: "Значение" } } )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question