Mongoosastic参考没有保存

时间:2017-03-23 22:12:07

标签: mongoose mongoose-schema mongoose-populate mongoosastic

我有这个:

smtp.gmail.com:465

和用户看起来像这样:

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 } 是有效的ID,我可以找到具有此ID的用户。

弹性纤维头上的

我看到了:

ObjectId("58ce87e7f86e5d36f6ccfb81")

为什么作者空了???

修改

我在底部添加了这个:

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

1 个答案:

答案 0 :(得分:0)

所以经过一天的mongoosastic.js调试后,我发现它需要填充,而作为填充路径,我不应该把集合名称,而是像这样的字段名称:

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