如何在猫鼬中将对象数组存储在数据库中

时间:2018-08-02 08:05:34

标签: node.js mongodb mongoose mongoose-schema

我的模式是

  branch_name: {type: String},
  semester_name: [{
    semester: {type: String},
    subject: [{
        subject_name: {type: String}
     }]
  }]

,结果来自前端-

{ 
   branch: 'it',
   semester: '5',
   subject: [
             { subject_name: 'math' }, 
             { subject_name: 'bio' } 
            ]
  }

我的用于插入代码的Api是-

   const new_branch = new Branch({
      branch_name: data.branch,
      semester_name: [{
        semester: data.semester,
        subject: [{
          subject_name: data.subject.subject_name
        }]
      }]
    });

    new_branch.save((err,result) =>{
      console.log(err);
      console.log(result);
    });

如何存储使用者名称。

我尝试了很多方法,但仍然无法正常工作

0 个答案:

没有答案