DEV Community

Perm Chao
Perm Chao

Posted on

NestJS with mongoose populate()

ตัว mongoose เองมี method populate() ที่ช่วยในการ $lookup อยู่แล้ว โดยเราสามารถใช้งานได้จากตัวของ model

 // declare constructor( @Inject(firstModelProviders[0].provide) private firstModel: Model<FirstModelDocument>, @Inject(secondModelProviders[0].provide) private secondModel: Model<SecondModelDocument>, ) {} // use const firstModelRepo = await this.firstModel.find().populate('secondModelForeignKey', '', this.secondModel).exec(); 
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
zodar93 profile image
Tarik MERABET

firstModelProviders[0].provide ???