我有两种模型,一种用于注释,一种用于类别
module.exports = mongoose.model("category", new Schema({
value: { type: String, default: ""
} ,
pinTo: { type: Array, default: []
},
partOf: { type: Array, default: [] }
}));
关于信函,我将有其他可以注释的模型,这些其他注释也将引用类别模型,但是现在是注释模型:
module.exports = mongoose.model("notes2", new Schema({
note: { type: String, default: "" },
title: { type: String, default: "" },
category: {
required: true,
type: String,
ref: "notes2-category"
}
}))
我看到的所有示例似乎都通过其ID引用了类别模型。在我的情况下,这将需要额外的工作,因为用户只需输入类别名称,而不仅是从预定义的集合中进行选择。
那么有没有办法引用类别模型的value
而不是ID?