繁体   English   中英

在RedExp上使用mongodb mongoose find

[英]Use mongodb mongoose find with RedExp

我读了一些文章,它适用于一个模型,但是当我尝试使用其他模型时,它不起作用。 我有这个:

function getimages(search, callback) {

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

       if (err) throw err;

       console.log(imagent);

       callback(imagent);

   });

}

console.log向我显示,即使RegExp字母与标题的某些字母重合,imagent对象也是空的。 也许我以错误的方式使用它,但是我不知道如何正确地使用它。 难道没有解决方案...?

谢谢前进!

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

应该是

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

因为那是功能参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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