mongoose populate alias code example
Example: 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 });