Node.js Mongoose如何引用相同的模式
所以我的问题陈述是这样的: -我有一个对象的模式Node.js Mongoose如何引用相同的模式,node.js,mongoose,Node.js,Mongoose,所以我的问题陈述是这样的: -我有一个对象的模式 const categorySchema = new mongoose.Schema({ name: { type: String, required: true, unique: true, minlength: 1, maxlength: 100 }, parent: { type: mongoose.Schema.Types.ObjectId, ref: 'cate
const categorySchema = new mongoose.Schema({
name: {
type: String,
required: true,
unique: true,
minlength: 1,
maxlength: 100
},
parent: {
type: mongoose.Schema.Types.ObjectId,
ref: 'categorySchema'
}
});
- 该父字段应该引用相同的模式,但是当我想要填充时,我得到了这个错误(这里我知道父字段在该对象上)
- 另一个问题是,当我从表中获取所有对象并填充它时,如何检查该字段“parent”是否在对象上。我知道如何手动操作,但有更简单的方法吗
谢谢大家! 必须将传递给mongoose.model()的名称作为第一个参数。我仍然不明白您的问题,请提供您尝试简化的手动方式。有关更多详细信息,请参阅此内容。您必须将传递给mongoose.model()的名称作为第一个参数。我仍然不明白你的问题,请提供你试图简化的手动方式。有关更多详细信息,请参阅此
error: MongooseError [MissingSchemaError]: Schema hasn't been registered for model "categorySchema".