title: Meteor client-side transform collections with external data (youtube)
body: <p>I'm working on a multi-tenant apps. Each app will have a video module which takes several youtube playlists/channels id as input.</p>
  
  <pre><code>Apps = {_id: "app01", playlists:['PL4IrNZLvgtED4RTH3xCf9085hwqKmb4lM','PLlYqpJ9JE-J8QIlua0KsBIxp-VQLyM_nO']}
  Apps = {_id: "app02", playlists:['id22','id23']}
  </code></pre>
  
  <p>and so on.</p>
  
  <p>When user redirect to address localhost:3000/app/:_id, the app subscribe to Meteor.subscribe('apps',_id).</p>
  
  <p>Now on the client side, i need to render a page that shows a list of playlists (or list of channels) with playlist's name, playlist thumbnail; and then if user clicks on the name/thumbnail, it displays another page with a list of videos belongs to that playlist/channel.</p>
  
  <p>What i am doing is to have a helper to retrieve all youtube playlists's info:</p>
  
  <pre><code>Template.Videos.helpers({
    myPlaylist:function(){
        return Apps.findOne({}, {
              transform: function (doc){              
                  playlists = doc.playlists;
                  doc.date = new Date(); //for testing
                  doc.videos = [];
                  for (var i=0;i&lt;playlists.length;i++){
                        console.log('find playlist: ',playlists[i]);
                        var url = 'https://gdata.youtube.com/feeds/api/playlists/'+playlists[i]+'?v=2&amp;alt=json';
                        $.getJSON(url, function(response){
                          var video={};
                          video._id = response.feed.yt$playlistId.$t;                     
                          video.title = response.feed.title;
                          video.entry = response.feed.entry;
                          videos.push(video); 
                        })//end getJSON
                      }//end for
                  doc.videos = videos;
                  console.log('Result:', doc);
                  return doc;
              }
          });
      }       
  });
  </code></pre>
  
  <p>The problem is in my template, I can see myPlaylist.date as a result of transform, but I cannot see myPlaylist.videos (although I see the console.log result has data)</p>
  
  <p>Does anyone has an idea how to solve this? Very appreciate!</p>