0

我有这个:

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,
});

和用户看起来像这样:

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

在我的数据库中,我看到了这个:

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

ObjectId("58ce87e7f86e5d36f6ccfb81")是一个有效的 ID,我可以找到具有此 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'}
    ],
});
4

1 回答 1

0

因此,在调试 mongoosastic.js 一天后,我发现它需要被填充,并且作为填充路径,我不应该放置集合名称,而是这样的字段名称:

ProjectSchema.plugin(mongoosastic, {
    esClient: esClient,
    populate: [
        {path: 'author', select: 'first_name last_name email'}
    ],
});
于 2017-03-24T10:19:31.250 回答