我有一个名为Profiles的服务器端mongo集合.
如果用户:adminId,我需要发布和订阅整个Profiles集合.
这样管理员就可以编辑,更新等...每个Profile集合项.
但我希望用户能够看到他们的个人资料记录.
所以我试过这个......
客户端
MyProfile = new Meteor.Collection("myprofile");
Meteor.subscribe('profiles');
Meteor.subscribe('myprofile');
Run Code Online (Sandbox Code Playgroud)
通用 - 客户端和服务器端
Profiles = new Meteor.Collection("profiles");
Run Code Online (Sandbox Code Playgroud)
服务器端 - 配置文件的发布和订阅工作正常.
// 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
}
});
});
Run Code Online (Sandbox Code Playgroud)
这是问题似乎开始的地方.Profiles.find返回集合项,因为我可以将它们输出到控制台服务器端.但由于某种原因,发布和订阅无效.客户端什么都没收到.
// return just the users profile as myprofile
Meteor.publish("myprofile", function() {
return Profiles.find({user: this.userId()});
});
Run Code Online (Sandbox Code Playgroud)
我有什么不妥的想法.我希望能够发布用户A可以插入,获取,更新,删除的记录集合,但用户B(C,D和E)只能看到他们的记录.
我认为这里的问题是你只需要一个集合:Profiles。
所以如果你只是删除有问题的行
MyProfile = new Meteor.Collection("myprofile");
Run Code Online (Sandbox Code Playgroud)
一切都应该正常工作(您将在集合中拥有两个数据集Profiles)。
| 归档时间: |
|
| 查看次数: |
4059 次 |
| 最近记录: |