提问者:小点点

从mongodb获取的数据显示在控制台中,而不显示在浏览器中[重复]


collection.find({"topicname":topicname},function(err,result){ 
if(result){   
    console.dir("Success from database =\n"+result.toString());
    console.dir(result);
    console.log("This is it"+result);
    res.send("Hello "+result);
}
});

结果以Json格式显示在console中,但在浏览器中获取时,它显示Hello[object object]。使用的数据库为MongoDb


共1个答案

匿名用户

res.send(“hello”+json.stringify(result));

这会将JSON对象转换为字符串,然后在与另一个字符串连接时将其适当地呈现在页面上,就像您正在做的那样。

json.stringify