1
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;
我在CollageSchema引用UniversitySchema的_id,但它會採取任何university_id不會在大學表存在。請幫幫我。謝謝
是'UniversitySchema'的'university.js'模型名稱?就像'collage'是'CollageSchema'的模型名稱一樣。 –
因爲那個錯誤。大學是大學模型 –