我正在尝试将 mongoosastic 插入我的 Keystone JS 应用程序并填充关系字段。找不到文档,并且由于 keystone 包装了模式模型,因此需要对 mongoose 文档进行一些翻译。有人可以告诉我我做错了什么吗?
var keystone = require('keystone');
var Types = keystone.Field.Types;
var mongoose = (keystone.mongoose);
var deepPopulate = require('mongoose-deep-populate')(mongoose);
var mongoosastic = require('mongoosastic');
var ProductCategory = keystone.List('ProductCategory').schema;
var Product = new keystone.List('Product', {
map: { name: 'title' },
autokey: { path: 'slug', from: 'title', unique: true },
track: true,
});
Product.add(
'Optional', {
volume: { type: String },
price: { type: Types.Number },
},
'Taxonomy', {
category: {
type: Types.Relationship,
ref: 'ProductCategory',
index: true,
many: true,
es_schema:ProductCategory,
es_indexed: true,
es_type: 'nested',
es_include_in_parent: true
},
}
);
Product.schema.plugin(deepPopulate);
Product.schema.plugin(mongoosastic, {
hosts: [
'host here'
]
populate: [
{path: 'category'}
]
})
Product.defaultColumns = 'title, brand, category, state|20%';
Product.register();