是否有可能在 mongoose 中有嵌套模式并在子级上有一个必需的验证器?像这样的:
const userSchema = new mongoose.Schema({
name: {
type: String,
required: true
}
});
const eventSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
host: {
type: userSchema,
required: true
}
});
我在文档中找不到任何内容。谢谢。
最佳答案
是的,您的架构是正确的。
mongoose 嵌套模式(子文档)的文档可以在 here 找到
关于node.js - Mongoose 可以需要子文档吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43620930/