Filter to display relevant users



Lets say i have the collection/schema set up to allow the following insertion:

Friendship.insert({owner: this.userId, friends: [{userId: 'a74YuMtpw9h5hHari', verified: true}], createdAt: new Date(), updatedAt: new Date()});

In my publications i can retrieve all my friends simply by calling this function:

let relationship = Friendship.findOne({'owner': this.userId}); 

Now, i want to return the filtered users to the client to display them(aka, everyone who’s userId matches my collection). I’ve tried running something like

return Meteor.users.find({_id: {$in: relationship.friends}});

but i quickly realised that since i designed .friends as an object inside an array it won’t let me use the $in function.

Any pointers? :slight_smile:


I’ll just point you in the direction of Socialize, specifically the Friendships package

$in:, function(friend) { return friend.userId })