Is it possible to retrieve specific user data (e.g. profile.name
or even something else within profile
object) with meteor-presence instead of returning userId? Or should I collect all userIds from Meteor.presences
and then query Meteor.users
with each userId
to get the data I need?
问问题
261 次
1 回答
2
Yes that is the best way to do it. You could use transform in your query too!
Meteor.presences.find({}, {transform:function(doc) {
var user = Meteor.users.findOne({_id:doc.userId});
if(user) doc.profile = user.profile;
return doc;
}
});
You can use this query in your template helper or pretty much anywhere else so that it now has a profile
object to match the user. Make sure though all your users in your user collection are published in a safe way.
于 2013-05-07T16:45:09.257 回答