Regex 将mongodb mongoose find与RedExp一起使用
我读了一些帖子,其中一个模型可以使用,但当我尝试其他模型时,它不起作用。我有这个:Regex 将mongodb mongoose find与RedExp一起使用,regex,node.js,mongodb,mongoose,Regex,Node.js,Mongodb,Mongoose,我读了一些帖子,其中一个模型可以使用,但当我尝试其他模型时,它不起作用。我有这个: function getimages(search, callback) { imagenmodel.find({ title: new RegExp(search) }, function (err, imagent){ if (err) throw err; console.log(imagent); callback(imagent); });
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对象为空,即使RegExp字母与标题的某些字母重合。也许我用错了,但我不知道如何正确使用。这有什么解决办法
谢谢你的预付款
imagenmodel.find({ title: new RegExp(reg) }, function (err, imagent){
应该是
imagenmodel.find({ title: new RegExp(search) }, function (err, imagent){
因为这是函数参数。True!我编辑了,我写错了。代码如您所说,但仍然不起作用。您可以添加搜索值和正在搜索的某些标题。也许您也可以添加模式定义