Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 将mongodb mongoose find与RedExp一起使用_Regex_Node.js_Mongodb_Mongoose - Fatal编程技术网

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!我编辑了,我写错了。代码如您所说,但仍然不起作用。您可以添加搜索值和正在搜索的某些标题。也许您也可以添加模式定义