1
notifications
을 여러 개 보유 할 수있는 users
모델이 있습니다. NotificationSchema
에서 notifier
은 사용자 ID를 보유하고 있으며 users
모델을 참조합니다. 다음 쿼리를 실행할 때 :몽구스 - 참조 된 모델의 필드를 제한
User.find().populate('notifications.notifier').exec(function(err,users){
//users[0].notifications[0].notifier
//I am getting all fields from the referenced user
//I don't want the whole document but some fields only
});
어떻게 누군가가 특정 모델을 참조 할 때 사용할 수있는 필드를 제한/제한 할 수 있습니까? 여기
내가
NotificationSchema
에 대해 별도의 model
이없는, BTW users
모델
var NotificationSchema =new Schema({
notifier : {type:Schema.Types.ObjectId, ref:'users'},
//How could I say :
//notifier : {type:Schema.Types.ObjectId, ref:'users', fields:['_id', 'name']}
//because I know what fields do I need from referenced model for this Schema.
__SOME__
__OTHER__
__FIELDS__
});
var UsersSchema = new Schema({
name : {given:String, middle:String, family:String}
email:String,
password:String,
notifications : [NotificationSchema]
});
var Users = mongoose.model('users', UsersSchema);
입니다.
이 기능을 사용할 수없는 경우 어떻게 수동으로 구현할 수 있습니까? 나는 몇몇 문서를 놓쳤는가? 제게는 robust
방법을 알려주세요.