最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

后呼吁,复杂的架构猫鼬

IT培训 admin 4浏览 0评论

后呼吁,复杂的架构猫鼬

想知道如何使一个复杂的模型合适的岗位要求

app.post('/tree',(req,res)=>{
    var tree = new Tree({
        firstName: req.body.firstName,
        middleName: req.body.middleName,
        lastName: req.body.lastName,
        alias:  [],
        father: req.body.father,
        mother: req.body.mother,
        relationship: [
            {
                 relation: req.body.relation,
                 children: []
            }
        ]
    });
})

这是架构

var mongoose = require('mongoose');
var ObjectId = mongoose.Schema.Types.ObjectId;

var schema = new mongoose.Schema({
    firstName: {
        type: String,
        required: true,
        minlength:1,
        trim:true
    },
    middleName: {
        type: String,
        trim: true
     },
     lastName: {
         type: String,
         trim: true
     },
     alias:  [String],
     father: ObjectId,
     mother: ObjectId,
    relationship: [
        {
            relation: ObjectId,
            children: [ObjectId]
        }
    ]    
 });

 var Tree = mongoose.model('Tree',schema);

 module.exports = {Tree};

即时通讯新编程所以我很抱歉,如果它是一个愚蠢的问题。希望我provied细节足以得到正确的答案。

回答如下:

为了节省您的tree可以使用save()功能,这样tree.save()。变更后,它看起来像这样

app.post('/tree',(req,res)=>{
    var tree = new Tree({
        firstName: req.body.firstName,
        middleName: req.body.middleName,
        lastName: req.body.lastName,
        alias:  [],
        father: req.body.father,
        mother: req.body.mother,
        relationship: [
            {
                 relation: req.body.relation,
                 children: []
            }
        ]
    });
    tree.save().then(err => {
      if (err) return res.send(500); // Error while saving

      res.send(201); // Return status code Created => Success
    });
})

注意:您发送POST请求到您的HTTP(S)服务器,而不是MongoDB的

后呼吁,复杂的架构猫鼬

想知道如何使一个复杂的模型合适的岗位要求

app.post('/tree',(req,res)=>{
    var tree = new Tree({
        firstName: req.body.firstName,
        middleName: req.body.middleName,
        lastName: req.body.lastName,
        alias:  [],
        father: req.body.father,
        mother: req.body.mother,
        relationship: [
            {
                 relation: req.body.relation,
                 children: []
            }
        ]
    });
})

这是架构

var mongoose = require('mongoose');
var ObjectId = mongoose.Schema.Types.ObjectId;

var schema = new mongoose.Schema({
    firstName: {
        type: String,
        required: true,
        minlength:1,
        trim:true
    },
    middleName: {
        type: String,
        trim: true
     },
     lastName: {
         type: String,
         trim: true
     },
     alias:  [String],
     father: ObjectId,
     mother: ObjectId,
    relationship: [
        {
            relation: ObjectId,
            children: [ObjectId]
        }
    ]    
 });

 var Tree = mongoose.model('Tree',schema);

 module.exports = {Tree};

即时通讯新编程所以我很抱歉,如果它是一个愚蠢的问题。希望我provied细节足以得到正确的答案。

回答如下:

为了节省您的tree可以使用save()功能,这样tree.save()。变更后,它看起来像这样

app.post('/tree',(req,res)=>{
    var tree = new Tree({
        firstName: req.body.firstName,
        middleName: req.body.middleName,
        lastName: req.body.lastName,
        alias:  [],
        father: req.body.father,
        mother: req.body.mother,
        relationship: [
            {
                 relation: req.body.relation,
                 children: []
            }
        ]
    });
    tree.save().then(err => {
      if (err) return res.send(500); // Error while saving

      res.send(201); // Return status code Created => Success
    });
})

注意:您发送POST请求到您的HTTP(S)服务器,而不是MongoDB的

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论