Answer the question
In order to leave comments, you need to log in
How to find data by incomplete match in mongoose?
I need to find all users in the database by part of their name.
For example, by complete coincidence:
person.find({"name.nameToDisplay": req.body.name},
function(err,data){
res.json(data);
});
Those. if I enter the name "Paul" it will find and if I enter "Pa" there will be an empty array.
Answer the question
In order to leave comments, you need to log in
Found a solution:
person.find(
{
"name.nameToDisplay": new RegExp(req.body.name, 'i')
}, function(err,data){
res.json(data);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question