Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to create alias in populate moongoose + nodejs

var countrySchema = new mongoose.Schema({
    capitalId: {type:String}
});

countrySchema.virtual('capital',{
    ref: 'City',
    localField: 'capitalId',
    foreignField: '_id',
    justOne: true
});

countrySchema.set('toObject', { virtuals: true });
countrySchema.set('toJSON', { virtuals: true });
Source by github.com #
 
PREVIOUS NEXT
Tagged: #create #alias #populate #moongoose #nodejs
ADD COMMENT
Topic
Name
4+8 =