MrMangado
MrMangado

Reputation: 993

Use mongodb mongoose find with RedExp

I read some post, and it works with one model, but when I try it with other models, it doesn't works. I have this:

function getimages(search, callback) {

   imagenmodel.find({ title: new RegExp(search) }, function (err, imagent){

       if (err) throw err;

       console.log(imagent);

       callback(imagent);

   });

}

The console.logshows me that the imagent object is empty, even if the RegExp letters coincide with some letters of a title. Maybe I use it in a wrong way, but I don't know how to do it properly. Ano solution for this...?

Thank's advance!

Upvotes: 0

Views: 149

Answers (1)

topek
topek

Reputation: 18979

imagenmodel.find({ title: new RegExp(reg) }, function (err, imagent){

should probably be

imagenmodel.find({ title: new RegExp(search) }, function (err, imagent){

because that's the function parameter.

Upvotes: 1

Related Questions