我想编辑我的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方法的帮助。我一直在尝试不同的方法,但是没有一个起作用。
添加回答
举报
0/150
提交
取消