我有以下mongoose架构: var ReviewSchema = new Schema({ title: String, details: String, user: {type: ObjectId, ref:'User'},});var SubjectSchema = new Schema({ name: {type: String, required: true}, website: {type: String, index: { uniq
var ReviewSchema = new Schema({ title: String, details: String, user: {type: ObjectId, ref:'User'}, }); var SubjectSchema = new Schema({ name: {type: String, required: true}, website: {type: String, index: { unique: true }}, review: {type: [ReviewSchema], es_indexed:true} });
我有另一个在Review中引用的User模式.
我尝试了mongoosastic插件,但我找不到索引引用架构的方法.我想索引评论用户的姓名.所以我只是使用了弹性搜索客户端.
每次创建/更新/删除审阅时,我都会在数据库中查找并使用从数据库中重新获取的值更新弹性搜索索引.更新嵌入式架构时,是否有更好的方法来更新索引?谢谢
这可以使用 mongoosastic完成,在Mongoose中有一个选项,如mongoosastic,使用它可以索引mongoose引用.ReviewSchema.plugin(mongoosastic, { populate: [ {path: 'User', select: 'name'} ] })
您可以在文档here中找到有关此内容的更多信息.