In Meteor, how can I publish one collection of mongo server-side mongo under different names?

I have a server side mongo assembly called Profiles.

I need to publish and subscribe to the entire collection of profiles if the user is: adminId.

Thus, the administrator can edit, update, etc. each item in the profile collection.

But I want users to be able to see their record in the report.

So, I tried this ...

CLIENT PARTY

MyProfile = new Meteor.Collection("myprofile");
Meteor.subscribe('profiles');
Meteor.subscribe('myprofile');

GENERAL - CUSTOMER AND SERVER

Profiles = new Meteor.Collection("profiles");

SERVER SIDE - Publishing and subscribing to profiles work 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
        } 
    });
});

This is where the problem begins. Profiles.find returns the elements of the collection, because I can output them to the console server. But for some reason, publication and subscription do not work. The client does not receive anything.

//  return just the users profile as myprofile
Meteor.publish("myprofile", function() {
  return  Profiles.find({user: this.userId()});
});

, . , A , , , , B (C, D E) .

+5
4

. - , :

/

+3

, MongoDB, . , ( ).

Group , DBRefs Profile ( , Profile ).

; ( ) , DBrefs , ( Group).

+1

, , , , . Profiles, , pub/sub- "myprofile", , ... , "myprofile" "" . "myprofile" . , () "myprofile", . (Meteor/MongoDB , , , .)

+1

I think the problem is that you only need one collection: Profiles.

So, if you just delete the offensive line

MyProfile = new Meteor.Collection("myprofile");

Everything should work fine (you will have both datasets in the collection Profiles).

0
source

All Articles