title: Meteor get usernames from userId, easier method
body: <p>Using Meteor:</p>
  
  <p>I have a list of messages in Messages which store a userId.</p>
  
  <pre><code>Messages = new Mongo.Collection('messages'); 
  
  // example of message data:
  
  {
  authorId: 'XFdsafddfs1sfd', // corresponding to a Meteor.userId
  content: 'some Message'
  }
  </code></pre>
  
  <p>And I'm publishing both the messages and the existing users.</p>
  
  <pre><code>Meteor.publish('messages', function () {
    return Messages.find({});
  });
  
  Meteor.publish('users', function () {
    return Meteor.users.find({});
  });
  </code></pre>
  
  <p>Currently I can grab the list of messages and add the usernames based on the userIds. Since users can change their usernames &amp; profile information, it doesn't make sense to add user data to the collection, just the userIds.</p>
  
  <pre><code>var messages = Messages.find({}).fetch();
  var messages.forEach(function(message) {
      message.username = Meteor.users.find(message.authorId).fetch() [0].username; // ugly
    });
  </code></pre>
  
  <p>This code works, but involves a lot of wasteful calls. I want to know how to accomplish this in a better way.</p>
  
  <blockquote>
    <p>In Meteor, what is the most efficient &amp; cleanest way to pair user data with a collection containing userIds? </p>
  </blockquote>