简体   繁体   中英

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.log shows 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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM