mongodb - 从数据库中取出的数据是什么对象?
阿神
阿神 2017-05-02 09:24:47
0
1
586

从数据库中取出的数据响应到页面上,需要转化为JSON对象吗?为什么?

router.get('/api/getArticles', (req, res) => {
  db.Article.find(null, 'title date content', (err, doc) => {
    if (err) {
      console.log(err)
    } else if (doc) {
      res.send(JSON.stringify(doc))
    }
  })
})

对数据库的了解不是很多,可能问题也问的不好,请多多指教。

阿神
阿神

闭关修行中......

reply all(1)
淡淡烟草味

The returned doc is an object.

You can print the type and value of doc in your code, which may make it easier for you to understand.

console.log(typeof doc);

console.log(doc);

For reference.

Love MongoDB! Have Fun!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!