我之所以提出这个问题,是因为我在研究时很难提出正确的问题。我希望澄清:
我有两个模式:
家长[团队]:
const EquipaSchema = new mongoose.Schema({
trab1: {
type: Schema.Types.ObjectId,
required: true,
ref: 'Trab'
},
trab2: {
type: Schema.Types.ObjectId,
required: true,
ref: 'Trab'
},
trab3: {
type: Schema.Types.ObjectId,
required: true,
ref: 'Trab'
},
teamName: {
type: String,
required: true
},
marcsEquipa: [{
type: Schema.Types.ObjectId,
ref: 'Marcacao'
}]
},
{collection: 'Equipas'})
和儿童[项目]:
const MarcacaoSchema = new mongoose.Schema({
name: { type: String, required: true },
email: { type: String, required: true },
date: { type: Date, required: true},
hour: { type: String, required: true},
type: { type: String, required: true},
address: {type: String, required: true},
state: {type: String, default: 'Pendente'},
// equipa: { type: Schema.Types.ObjectId, ref: 'Equipa' },
equipa: {
type: String,
default: 'Não'
},
cliente: {
type: Schema.Types.ObjectId,
ref: 'User'
},
aval_admin: {
type: String,
default: "Sem Avaliação pelo Manager"
},
descricao: {
type: String,
default: "Sem Descrição"
},
aval_client: {
type: String,
default: "Sem Avaliação do Cliente"
},
avaliado: {
type: Boolean,
default: false
},
team: {
type: Schema.Types.ObjectId,
ref: 'Equipas'
}
},
{collection: 'Marcacao'}
我的目标是:当一个团队被删除时,团队数组['marcsequipa[]']中的所有项目都会更新为{team:null},这样我就可以为同一个项目分配一个新团队。
我曾经尝试过使用中间件,但它的一些用法现在已经被弃用,并且没有成功。解决这个问题的正确方法是什么?
先谢谢你
1条答案
按热度按时间mwkjh3gx1#
这就是解决办法。其中req.params.\u id是团队id。