I'm trying to publish "friends" from the users Collection. There is a field on every account that saves all friend-ids (called addressbook). But publishing doesn't work I'm only getting my own account (as non admin) e.g. if i call Meteor.users.find().fetch() on the console. If I do it the way above the console logs the following:
I20140107-17:22:38.492(1)? ---------------------------------------[object Object]
I20140107-17:22:38.497(1)? [ { _id: 'X6XXyD64AW4CvXG6m',
I20140107-17:22:38.498(1)? createdAt: Tue Jan 07 2014 17:10:43 > GMT+0100 (CET)
I20140107-17:22:38.498(1)? emails: [ [Object] ],
I20140107-17:22:38.498(1)? services: { password: [Object], resume: [Object] },
I20140107-17:22:38.499(1)? username: 'test' } ]
so no addressbook is presented
Here a snippet of my code:
Server:
Meteor.publish("users", function(){
if (Roles.userIsInRole(this.userId, ["admin"]))
return Meteor.users.find();
else
return Meteor.users.find({_id : this.userId}, {fields: {username: 1, id_:1, emails:1, addressbook:1, createdAt:1}});
});
Meteor.publish("friends", function(){
var addressbook = Meteor.users.find({_id: this.userId}, {limit:1} , {fields: {addressbook:1}});
console.log("---------------------------------------" + addressbook);
console.log(addressbook.fetch());
//return Meteor.users.find({_id :{ $in : addressbook}}, {fields : {username:1, emails: 1}});
Client:
Deps.autorun(function() {
Meteor.subscribe("friends");
Meteor.subscribe("users");
});
How do i publish the users which are stored by their ids to the field addressbook (or at least their emails and usernames)? Is there a better way to combine the publish ?
Thanks in advance!