mongodb - What object is the data taken out from the database?
阿神
阿神 2017-05-02 09:24:47
0
1
670

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.

阿神
阿神

闭关修行中......

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