MongoDB
 sql >> Datenbank >  >> NoSQL >> MongoDB

Virtuell mit Mongoose bevölkern

Sie können das Pfadattribut für Deep-Linking verwenden, dies würde auch für Array-Typen funktionieren.

documentId: { type: mongoose.ObjectId, ref: 'Media' },
schema.virtual('educationDocument', {   
    ref: 'Media', // the collection/model name
    localField: 'education.documentId',
    foreignField: '_id',
    justOne: true, // default is false });
const users = await User.find({})
    .populate({ path: 'educationDocument' })
    .populate({ path: 'experienceDocument' })
    .populate({ path: 'certificationDocument' })
    .execPopulate()