Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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
Node.js 如何从mongodb向express js中的get方法发送数据_Node.js_Express - Fatal编程技术网

Node.js 如何从mongodb向express js中的get方法发送数据

Node.js 如何从mongodb向express js中的get方法发送数据,node.js,express,Node.js,Express,我正在尝试从mongodb访问数据,并将其发送到express js中的get方法。我能够访问数据,但无法将其发送到get方法。 这是我的密码 app.get('/', function(req, res){ res.send('this is test for mongo db'); Person.find(function(err, response){ var data = response; console.log(data); res.send(data);

我正在尝试从mongodb访问数据,并将其发送到express js中的get方法。我能够访问数据,但无法将其发送到get方法。 这是我的密码

app.get('/', function(req, res){
 res.send('this is test for mongo db');

 Person.find(function(err, response){
   var data = response;
   console.log(data);
   res.send(data);
 });
});
这里是console.log(数据正在工作),但res.send(数据)不工作。有什么建议吗

res.send用于向客户端发送响应,仅使用一次

使用res.send一次,在代码中使用res.send两次

app.get('/', function(req, res){

 Person.find(function(err, response){
     if(err){
       console.log(err)  
       return res.send('error');      
     }

     if(!err && response){
       console.log(response)
       res.send(response);
     } 
   });
});

你已经发送了。。。