Does it need to be converted into a JSON object when the data retrieved from the database is responded to the page? Why?
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))
}
})
})
I don’t know much about databases, so I may not have asked the right questions, so please give me some advice.
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!