I have two models called TodaysDeals and Products
export class TodaysDeal {
_id: ObjectId;
@Property({ required: true, type: Schema.Types.ObjectId, ref: "ProductsModel" })
products: Products
}
export const TodaysDealModel = getModelForClass(TodaysDeal);
and
export class Products {
_id: ObjectId;
@Property({ required: true })
productName: String;
}
export const ProductsModel = getModelForClass(Products);
I'm trying to populate the joined data, but i did'nt get the joined result.it has only contain product._id.
here is my code
let data = await TodaysDealModel.find().populate("ProductsModel");
extending on what @Vishnu said: you have 2.5 problems
populateyou need to use the field name instead of the referenced model nameProductsModel, at least not from what your code sample provided, look here to see how typegoose generates class/model names and hereand another "smaller" problem is, that you use
Productsas type, whereRef<Products>would be correctyour corrected code would look like: