发布复杂模式猫鼬的电话

时间:2019-02-05 13:14:46

标签: node.js mongodb post mongoose

想知道如何为复杂的模型提出适当的后期要求

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};

我是编程新手,所以很抱歉,这是一个愚蠢的问题。 希望我提供的详细信息足以得到正确的答案。

1 个答案:

答案 0 :(得分:0)

为了保存您的isDishFavorited(BuildContext context) async{ SharedPreferences prefs = await SharedPreferences.getInstance(); if(prefs.getString(widget.dish_name) != null){ setState(() { _isFavorited = true; }); } debugPrint("isfavorite inside method is" + _isFavorited.toString()); } ,您可以使用setState函数,例如tree。更改后,它看起来像这样

save()

注意:您将POST请求发送到http服务器,而不是MongoDb