How to use mongoosastic plugin with typegoose

352 Views Asked by At

I am wondering how to install and use mongoosastic(^4.6.0) with typegoose (@typegoose/typegoose: "^7.4.5"). I was unable to install @types/mongoosastic package. So to setup the plugin I did:

import { prop, getModelForClass, index, plugin } from "@typegoose/typegoose";
var mongoosastic = require('mongoosastic');


@index({ location: '2dsphere' })
@plugin(mongoosastic)
export class Vehicle {
...
}

export const VehicleModel = getModelForClass(Vehicle);

When I save a new vehicle object using typegoose (await VehicleModel.create({...} as Vehicle);) the piece of data is immediately sync with elasticsearch.

The issue now is I cannot use do Vehicle.search(...) on the Vehicle class because the .search method is not added by the plugin as indicated in the mongoosastic docs. How is this done??? Thank you in advance.

0

There are 0 best solutions below