0

나는이있다 :Mongoosastic 참조가 저장되지

{ 
"_id" : ObjectId("58d4456fd3d52632e010d377"), 
"author" : ObjectId("58ce87e7f86e5d36f6ccfb81"), 
"projectId" : "J0MXYM1S872Y3", 
"category" : "gaming", 
"title" : "The Project", 
"description" : "This is the project.", 
"participants" : [ ], 
"__v" : 0 
} 

ObjectId("58ce87e7f86e5d36f6ccfb81")가 유효한 ID입니다 :이 참조 내 데이터베이스에

const UserSchema = new Schema({ 
    userId: String, 
    first_name: String, 
    last_name: String, 
    email: String, 
    password: String, 
}); 

:

const ProjectSchema = new Schema({ 
    projectId: String, 
    author: { type: Schema.Types.ObjectId, ref: 'User', es_indexed: true, es_schema: getUserModel().schema, es_select: 'first_name last_name email' }, 
    participants: [String], 
    category: String, 
    title: String, 
    description: String, 
}); 

및 사용자는 다음과 같다 이 ID를 가진 사용자를 찾을 수 있습니다. elastisearch 머리에

나는이를 참조하십시오

"_source": { 
"projectId": "J0MXYM1S872Y3", 
"author": { }, 
"participants": [ ], 
"category": "gaming", 
"title": "The Project", 
"description": "This is the project." 
} 

왜 저자가 비어 ???

편집

나는 바닥에이 추가 :

ProjectSchema.plugin(mongoosastic, { 
    esClient: esClient, 
    populate: [ 
     {path: 'users', select: 'first_name last_name email'} 
    ], 
}); 

답변

0

그래서 필요로 내가 발견 한 mongoosastic.js 디버깅의 하루 채워하는 후, 그리고 채우기 경로 나 컬렉션 이름을 넣지 말고 다음과 같이 필드의 이름을 넣으면 안됩니다 :

ProjectSchema.plugin(mongoosastic, { 
    esClient: esClient, 
    populate: [ 
     {path: 'author', select: 'first_name last_name email'} 
    ], 
});