对于复杂的架构,我应该如何使用body-parser?

时间:2018-07-13 09:35:24

标签: mongodb mongoose mongoose-schema body-parser .post

我想根据以下模式使用body-parser将内容发布到mongodb:

var NodesSchema = new Schema({
  Name: String,
  Distribution: [{mp: String, ln: String}],
  Volume: String
});

当我使用以下标准模式进行测试时,它工作得很好:

var NodesSchema = new Schema({
  Name: String,
  Distribution: String,
  Volume: String
});

在这种情况下,我有:

.post(function(req, res) {
    var node = new Node();

    node.Name = req.body.Name;
    node.Distribution = req.body.Distribution;
    node.Volume = req.body.Volume;

    node.save(function(err) {
      if (err)
        res.send(err);
      res.json({ message: 'Node successfully added!' });
    });
  }); 

0 个答案:

没有答案
相关问题