Why is mongoosastic populate / elastic search not populating one of my references? I'm getting an empty object

我的未来我决定 提交于 2019-12-04 06:52:58
NoobSter

I've got it working, but it differs much from the examples given on npm / github.

I had to remove the es_schema: Style, (as I had accidentally done for brand, which was why it worked). I had to add the es_type: "nested" / es_include_in_parent, which I gathered from elasticsearch and mongoosastic documentation.

I'm not sure this is intended, but it seems to work:

style: {type: mongoose.Schema.Types.ObjectId, ref: 'Style',
    es_type:'nested', es_include_in_parent:true},

I now get : style: [Object] as needed, when I console.log results.hits .


Below is the example given in npm , which did not work for me:

var Comment = new Schema({
    title: String
  , body: String
  , author: String
});


var User = new Schema({
    name: {type:String, es_indexed:true}
  , email: String
  , city: String
  , comments: {type: Schema.Types.ObjectId, ref: 'Comment',
    es_schema: Comment, es_indexed:true, es_select: 'title body'}
})

User.plugin(mongoosastic, {
  populate: [
    {path: 'comments', select: 'title body'}
  ]
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!