2013-03-17 68 views
0

我阅读了一些文章,它适用于一个模型,但是当我尝试使用其他模型时,它不起作用。我有这样的:使用mongodb mongoose查找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显示我的imagent对象为空,即使正则表达式信件,标题中的一些字母一致。也许我以错误的方式使用它,但我不知道如何正确地使用它。 Ano解决方案...?

谢谢先进!

回答

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

大概应该是

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

,因为这是函数参数。

+0

真的!我编辑过,我写错了。代码如您所说,但仍然不起作用 – MrMangado 2013-03-17 21:33:41

+0

您可以添加搜索的值以及您正在搜索的某些标题。也许你也可以添加你的模式定义 – topek 2013-03-18 17:56:33