search

Home  >  Q&A  >  body text

mongodb - What object is the data taken out from the database?

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.

阿神阿神2845 days ago700

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味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!

    reply
    0
  • Cancelreply