mongodb - Publish and subscribe for a collection depending on a document field with different IDs with Meteor -


i building magnetic poetry game in meteor

http://test-magnets.meteor.com/

the homepage allows online play on same "fridge" want have option allows create own fridge without public disturbing it.

i used iron router generate url based on userid. magnets have fridgeid. fridgeid home page 1 , when user goes url based on userid, magnets fridgeid gets updated same userid.

currently when move magnet in homepage makes change in user's private fridge. possible use publish , subscribe or iron router update database magnets depending on generated fridgeid? suggestions appreciated. thanks

-john

here code have now.

iron router

router.map(function() { this.route('home', {     path: '/' }); var user = meteor.userid(); this.route('private', {     path: '/' + user   }); }); 

magnets collection

  if (meteor.isserver) {     meteor.publish('magnets', function(){    return magnets.find();  }); }   if (meteor.isclient) {   meteor.subscribe('magnets', function(){   return magnets.find();  }); } 

some helpers set fridgeid

template.home.events = { 'click #new-board': function() {     var user = meteor.userid();     var magnet = magnets.findone();     magnets.update({_id: magnet._id}, {$set: {fridgeid: user}});  } };  template.private.events = { 'click #group-fridge': function() {     var magnet = magnets.findone();     magnets.update({_id: magnet._id}, {$set: {fridgeid: 1}});  } }; 


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -