📜  如何在填充 moongoose + nodejs 中创建别名 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:46.633000             🧑  作者: Mango

代码示例1
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 });