繁体   English   中英

我如何在猫鼬中引用架构的 id

[英]How do I refer the id of schema in mongoose

 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。 请帮我。 谢谢

默认情况下,任何引用对象 ID 的架构中都没有任何验证您可以做的是设置一个同步验证并在其中进行findOne调用以进行验证。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM