M
M
Mikhailo Poberezhny2016-01-27 03:17:28
MongoDB
Mikhailo Poberezhny, 2016-01-27 03:17:28

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

1 answer(s)
M
Mikhailo Poberezhniy, 2016-01-27
@as_for_me

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 question

Ask a Question

731 491 924 answers to any question