我正在使用mongoose v6.0.0
,mongoosastic v5.0.0
和typescript
,当我在初始化插件并尝试正确设置类型后尝试以下代码时,它仍然告诉我PageModel.search
和插件引入的其他函数是undefined
。
import mongoose, { Schema, Document } from 'mongoose';
import mongoosastic, { MongoosasticModel, MongoosasticDocument } from 'mongoosastic'
export interface IPage extends Document, MongoosasticDocument {
user: string;
permissions: {
[key: string]: {
read: boolean;
write: boolean;
admin: boolean;
email: string;
};
};
style: {};
data: {
blockType: string;
properties: {};
children: [];
}[];
}
const PageSchema = new Schema({
user: String,
permissions: {},
style: {},
data: [
{
blockType: String,
properties: {},
children: [],
},
],
});
// -=- Elastic Search -=-
// ~ Check if Elastic Search info exists
if (!process.env.ELASTICSEARCH_URL) throw Error('Missing Elastic Search URL');
// ~ Add Elastic Search plugin
PageSchema.plugin(
mongoosastic,
{
clientOptions: {
nodes: [
process.env.ELASTICSEARCH_URL,
]
},
transform: (doc: IPage) => {
},
}
);
const PageModel = (mongoose.models.page || mongoose.model('page', PageSchema)) as mongoose.Model<IPage, MongoosasticModel<IPage>>;
// ~ PageModel.search is undefined here
export default PageModel;
我试过将mongoose升级到最新版本,通过documentation升级mongoose类型似乎没有太多信息。
1条答案
按热度按时间gmxoilav1#
只是输入错误的PageModel我切换的代码
到