I'm using mongoose v6.0.0, and mongoosastic v5.0.0 and typescript when I try the following code after initializing the plugin and trying to set the types correctly it still tells me that PageModel.search and other functions introduced by the plugin are 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;
I've tried upgrading mongoose to the latest version and upgrading the mongoose types by the documentation doesn't seem to have much info.
Just miss typed the PageModel I switched the code from
to