schema error mean app

后端 未结 1 1516
遥遥无期
遥遥无期 2021-01-26 15:30

I have a schema problem. I dont get the right schema in my api. here is my api :

var Meetup = require(\'./models/meetup\');

    module.exports.create = functio         


        
相关标签:
1条回答
  • 2021-01-26 15:51

    If req.body is undefined (as you wrote in the comments) then obviously new Meetup(req.body); cannot populate the new objects with any data (like {name: 'Text input'} or anything else) since it is called with undefined as an argument.

    Make sure you use the body-parser and that you pass the correct data in your request.

    Also, check for errors. Every callback that takes the err argument should be in the form of:

    module.exports.list = function (req, res) {
      Meetup.find({}, function (err, results) {
        if (err) {
          // handle error
        } else {
          // handle success
        }
      });
    }
    

    How to track the problem:

    • make sure you use the body-parser on the backend
    • make sure you pass the correct data on the frontend
    • make sure that the data passed by your frontend is in the correct place (body)
    • make sure that the data is in the correct format (JSON? URL-encoded?)
    • add console.log(req.body) after new Meetup(req.body); to know what you save
    • open the Network tab in the developer console of your browser and see what is transferred
    0 讨论(0)
提交回复
热议问题