const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const CollageSchema = new Schema({
collage_name: {
type: String,
required: [true, 'Name field is required']
},
university_id: {
type: [{
type: Schema.Types.ObjectId,
ref: 'university'
}]
},
type: {
type: String,
enum: ['autonomous', 'private'],
required: [true, 'type field is required']
}
});
const Collage = mongoose.model('collage', CollageSchema);
module.exports = Collage;
我参考了_id of UniversitySchema in CollageSchema,但它将采用大学表中不存在的任何university_id。请帮帮我。谢谢
发布于 2017-10-08 11:41:36
默认情况下,模式中没有对任何引用对象Id进行任何验证,您可以做的是设置一个同步验证,并在其中进行findOne调用以进行验证。
https://stackoverflow.com/questions/46628760
复制相似问题