从数据库中取出的数据响应到页面上,需要转化为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))
}
})
})
对数据库的了解不是很多,可能问题也问的不好,请多多指教。
淡淡烟草味2017-05-02 09:26:47
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!