I am currently facing an issue with publishing "friends" from the users Collection. Within each account, there is a field named addressbook that stores all friend-ids. Unfortunately, when trying to publish this information, I only receive my own account (as a non-admin) when running Meteor.users.find().fetch() in the console. The output in the console looks like this:
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' } ]
addressbook data is not being displayed
Here's a snippet of the code in question:
Server-side:
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-side:
Deps.autorun(function() {
Meteor.subscribe("friends");
Meteor.subscribe("users");
});
How can I successfully publish the users based on their ids stored in the addressbook field (or at least their emails and usernames)? Are there better ways to combine these publishes?
Thank you in advance!