we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "how to create alias in populate moongoose 2b nodejs"
Axel
06 Jan 2020
1var countrySchema = new mongoose.Schema({
2    capitalId: {type:String}
3});
4
5countrySchema.virtual('capital',{
6    ref: 'City',
7    localField: 'capitalId',
8    foreignField: '_id',
9    justOne: true
10});
11
12countrySchema.set('toObject', { virtuals: true });
13countrySchema.set('toJSON', { virtuals: true });