是否可以在字段中包含多个引用。如果没有,无论如何还有好的方法吗?
我试过这个:(2产品工作中的参考)
var productSchema = mongoose.Schema({
name: {
type: String,
required: true,
trim: true,
index: true
},
productNumber: {
type: Number,
required: true
},
client_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Client',
required: true
},
receiveDate: {
type: Date,
required: true
},
paymentDate: {
type : Date
},
deadline: {
type: Date,
required: true
},
remark: {
type: String,
default: null
},
productStaff: [{
staff: {
type : mongoose.Schema.Types.ObjectId,
ref: 'Staff'
},
assignment: {
type : mongoose.Schema.Types.ObjectId,
ref: 'Assignment'
}
}],
productItem: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'ProductItem',
default: null
}],
registrationDate: {
type: Date,
default: Date.now
}
});
但是我在添加数据时遇到了这个错误:
错误:“产品验证失败:产品执行:转换为数组失败以获取值\”[{staff:'594b63b184e6290c386baa3f',\ n赋值:'594b63b184e6290c386baa3f'},\ n {staff:'594b63b184e6290c386baa3g',\ n赋值: '594b63b184e6290c386baa3g'}] \“at path \”productStaff \“”
我是这样做的,因为我需要保存将使用相应作业完成产品的员工。
非常感谢。