Currently, my setup involves using mongoose v6.0.0
, mongoosastic v5.0.0
, and integrating typescript
. However, even after initializing the plugin and attempting to correctly set the types, I am encountering issues where functions like PageModel.search
introduced by the plugin are showing up as 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>>;
// ~ The issue arises with PageModel.search being undefined at this point
export default PageModel;
I have attempted upgrading mongoose to its latest version and also updating the mongoose types following the guidance provided in the documentation. However, none of these actions have resolved the issue.