I have a server side mongo collection called Profiles.
I need to publish and subscribe to the entire collection of Profiles if user: adminId.
That way the administrator can edit, updated, etc... each Profile collection item.
But I want users to be able to see their Profile record.
So I tried this...
CLIENT SIDE
MyProfile = new Meteor.Collection("myprofile");
Meteor.subscribe('profiles');
Meteor.subscribe('myprofile');
COMMON - CLIENT AND SERVER SIDE
Profiles = new Meteor.Collection("profiles");
SERVER SIDE - The publishing and subscribing of profiles works fine.
// this returns all profiles for this User
// if they belong to an ACL Group that has acl_group_fetch rights
Meteor.publish("profiles", function() {
var user_groups = Groups.find({users: this.userId()});
var user_groups_selector = [];
user_groups.forEach(function (group) {
user_groups_selector.push(group._id);
});
return Profiles.find( {
acl_group_fetch: {
$in: user_groups_selector
}
});
});
Here is where the problem seems to begin. The Profiles.find is returning collection items because I can output them to the console server side. But for some reason the publish and subscribe is not working. The client receives nothing.
// return just the users profile as myprofile
Meteor.publish("myprofile", function() {
return Profiles.find({user: this.userId()});
});
Any ideas what I am doing wrong. I want to be able to publish collections of records that User A can insert, fetch, update, delete but User B (C, D and E) can only see their record.