我正在使用 ElasticSearch 和 mongoosastic 在 MongoDB 和 ElasticSearch 之间同步数据。我想包含一个模式的属性,这是我研究中的另一个对象:我想显示具有我正在搜索的类别的文章。这些是我的 2 个模式:ArticleSchema 和 CategorySchema。文章包含一个名为“类别”的类别对象。
var ArticleSchema = new Schema({
created: {
type: Date,
default: Date.now
},
...
user: {
type: Schema.ObjectId,
ref: 'User'
},
categorie: {
type: Schema.ObjectId,
es_indexed:true,
ref: 'Category',
required: 'Le champ "Categorie" ne peut pas etre vide'
}
});
var CategorySchema = new Schema({
name: {
type: String,
default: '',
required: 'Please fill Category name',
trim: true
},
...
niveau: {
type: Number
}
});