亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Mongodb:如何通過我的API填充我的架構中引用的架構

Mongodb:如何通過我的API填充我的架構中引用的架構

蠱毒傳說 2021-03-29 15:08:07
我想編輯我的Api以便能夠填充引用的架構。這是我的架構:export const taskSchema = new Schema ({    user:{        type: String,        required: true    },    project: {         type: String,        required: true    },    issue: {        type: String,        required: true    },    title: {        type: String,        required: true    },    records : [{           _domain: {            type: Schema.Types.ObjectId,            ref: 'TaskDomains'        },        time: {            type:Number        }        }],           dateCreated: {             type: Date,        default: Date.now    }});我的taskDomain模式:export const TaskDomains = new Schema ({    label:{        type: String,        required: true    }});如何編輯以下post方法以填充引用的TaskDomain架構。這是我的方法:import * as mongoose from 'mongoose';import {taskSchema,TaskDomains} from '../models/tasks.model';import {Request, Response} from 'express';const Task = mongoose.model('Task', taskSchema);const domain = mongoose.model('domain', TaskDomains);export class taskController{public addNewTask (req: Request, res:Response){        let newTask = new Task();        newTask.user = req.body.user;        newTask.project = req.body.project;        newTask.issue = req.body.issue;        newTask.title = req.body.title;        newTask.dateCreated = req.body.dateCreated;        newTask.records = new domain(req.body._domain);        newTask.records = new domain(req.body._domain.label);        newTask.records = req.body.time;        newTask.save((err, task)=>{            if(err){                res.send(err);            }            res.json(task);        });    }    }我需要編輯post方法的幫助。我一直在嘗試不同的方法,但是沒有一個起作用。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號