I have two collections one contain User Profiles and other one contains User Friends userFriend contain array call friends and it will contain that particulater user's friends. the relationship between these two collections are user_id. i just wrote a function to get one users friends profiles and it is working. but i want to know if there any other better way than retrieving it from one by one. please find the method below.
import UserFriends from 'TruthHurts/collections/UserFriends';
import UserProfile from 'TruthHurts/collections/UserProfile';
getUserFriends: function(userId){
var resutls= [],userProfiles;
var UserFriendsList = UserFriends.findOne({userId: userId});
for(var i = 0; i < UserFriendsList.friends.length; i++){
userProfiles = UserProfile.findOne({userId: UserFriendsList.friends[i].friend_id});
if(userProfiles){
resutls.push(userProfiles);
}
}
return resutls;
}