node.js - Categories not found, Meteor subscription -


so, i'm looking have contents of categories collection of meteor application available @ times entire app. had read somewhere can specifying null first parameter (instead of name) meteor.publish function.

i used following code:

// categories meteor.publish(null, function() {     return categories.find(); }); 

when launch app, following error application starting (the above segment of code in <app>/server/publications/global.js):

exception sub id undefined referenceerror: categories not defined   @ [object object].meteor.publish.meteor.users.find.fields.username [as _handler] (app/server/publications/global.js:8:12)   @ maybeauditargumentchecks (packages/ddp/livedata_server.js:1617:1)   @ [object object]._.extend._runhandler (packages/ddp/livedata_server.js:950:1)   @ [object object]._.extend._startsubscription (packages/ddp/livedata_server.js:769:1)   @ packages/ddp/livedata_server.js:1437:1 

the weird thing is, says publication seems work fine. mongol reporting categories data available throughout app, , there no other places publish data, must coming call.

any thoughts? i'm sorta confused. should check see if categories exists inside sub before returns, maybe?

to add matt k said (because comments suck , there's bad code formatting in comments), possible example of code creates named collection , maintains synchronization of data between connected clients , server:

/lib/collections.js - runs on both server , client

categories = new mongo.collection('categories'); 

/server/publications.js

meteor.publish('categories', function() {     return categories.find(); }); 

/lib/router.js - (for iron router , tells paths wait until my_collection has been subscribed before loading)

router.configure({   loadingtemplate: 'loading',   waiton: function() {     return [       meteor.subscribe('categories')     ];   } }); 

now you did in op create un-named collection on server , publish connected clients:

http://docs.meteor.com/#/full/meteor_publish

/lib/collections.js

categories = new mongo.collection('categories'); 

/server/publications

meteor.publish(null, function() {     return categories.find(); }); 

what send data got categories.find(); client in form of collection has no name. since has no name, there no direct way tell when client has subscribed since doesn't have waiton for, there possible solution..

when "null" publish ready?

https://github.com/alanning/meteor-null-publish-test

but in summary, publishing null (un-named) collection client goofy hell since don't know when data available on each client. avoid if can , use standard pub/sub pattern described in upper part of post.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -