我有这个:
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."
}
答案 0 :(得分:0)
所以经过一天的mongoosastic.js调试后,我发现它需要填充,而作为填充路径,我不应该把集合名称,而是像这样的字段名称:
ProjectSchema.plugin(mongoosastic, {
esClient: esClient,
populate: [
{path: 'author', select: 'first_name last_name email'}
],
});