mongodb - Getting specific user data from Meteor Presence -


with meteor presence, can return userid's of usetrs online but. see how user object.

meteor.publish('userpresence', function() {   return meteor.presences.find({}, {fields: {state: true, userid: true}}); }); 

as can see im publishing collection , subscribing it:

meteor.subscribe('userpresence'); 

i have view has each block in online users:

<template name="presencelist">    <h1>{{onlinecount}}</h1>    {{#each onlineusers}}       {{> presencesingle}}    {{/each}} </template> 

and file has helpers in:

template.presencelist.helpers({     onlineusers: function() {     return meteor.presences.find();    },    onlinecount: function() {     return meteor.presences.find().count();    } }); 

my biggest struggle return user name in single user template.

any awesome, thanks.

add underscore package

mrt add underscore 

then can update onlineusers to

onlineusers: function() {   var users = _.map(meteor.presences.find().fetch(), function(user) {      return meteor.users.findone({_id :user.userid})   });   return users; } 

all doing above making new array returned objects meteor.users.findone({_id :user.userid}) using underscore's _.map see link

finally, presencesingle template

<template name="presencesingle">   <p>{{_id}}</p>   <p>{{createdon}}</p>   <p>{{emails.0.address}}</p>   <br/> </template> 

here returning _id, createdat , email address fields each user's mongo document. can return fields like. note handlebars syntax returning email address. emails array of 1 element access elements using emails.0 not emails[0]


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -