Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Nestes Schema virtual

I am trying to access the products collection in my find method. I added a .virtual method in order to access it but I currently get following error messsage:

MissingSchemaError: Schema hasn't been registered for model "ProductDocument".

So far my implementation:

export type PriceDocument = Price & Document;

@Schema({ timestamps: true })
export class Price {
  @Prop({
    ref: 'ProductDocument',
    required: true,
  })
  uid: string;

  @Prop()
  standardPrice: number;

  @Prop({ required: true })
  startDate: Date;

  @Prop()
  endDate: Date;
}

export const PriceSchema = SchemaFactory.createForClass<Price>(Price)
  .index({
    uid: 1, startDate: 1, endDate: 1,
  }, { unique: true });

PriceSchema.virtual('products', {
  ref: 'ProductDocument',
  localField: 'uid',
  foreignField: 'uid',
});

ProductPriceSchema.set('toObject', { virtuals: true });
ProductPriceSchema.set('toJSON', { virtuals: true });

This is how I try to access it in my find method

    const productPriceDocument = await this.productPrice.find({
      $and: queries, // dynamic queries
    }).populate('products').exec();
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!