【问题标题】:Data fetched from mongodb displayed in console and not in browser [duplicate]从 mongodb 获取的数据显示在控制台而不是浏览器中 [重复]
【发布时间】:2016-06-23 07:38:39
【问题描述】:
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 格式显示在控制台中,但是在浏览器中获取时显示 Hello [object Object]。 使用的数据库是 MongoDb

【问题讨论】:

    标签: mongodb express


    【解决方案1】:

    res.send("Hello " + JSON.stringify(result));

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

    JSON.stringify

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      • 1970-01-01
      • 2011-06-30
      • 2019-08-29
      • 2020-12-17
      • 2018-06-08
      相关资源
      最近更新 更多