TypeError: db.collection is not a function

后端 未结 18 2523
青春惊慌失措
青春惊慌失措 2020-11-27 03:09

I am trying to post data to database that I have created on mLab and I am getting this error but I don\'t know whats going wrong.I also have read previously asked question o

18条回答
  •  臣服心动
    2020-11-27 03:14

    module.exports = function(app, db) {
      app.post('/notes', (req, res) => {
      const note = { text: req.body.body, title: req.body.title };
      db.collection('notes').insert(note, (err, result) => {
    ...
    

    db -> client

    module.exports = function(app, client) {
      var db = client.db("name");
      app.post('/notes', (req, res) => {
      const note = { text: req.body.body, title: req.body.title };
      db.collection('notes').insert(note, (err, result) => {
    ...
    

提交回复
热议问题