Meteor: what is the right way to add custom settings object to users collection? -



Meteor: what is the right way to add custom settings object to users collection? -

there multiple examples on publish/subscribe not clear on best practice storing custom info in in-built "users" collection in meteor (especially in new possibility of template specific collections).

for example, need store user browse history - accessible through meteor.user().settings.history.lastvisited[]

the challenge is:

is special publish / subscribe required above? (the reason being, assuming users collection published , available on client side - need another?) how take care of border cases user new , hence settings.history object may not defined? can have special publish automatically takes care of creating empty object if settings undefined? how it?

i did :

// server side meteor.publish('usersettings', function (maxrows) { if (this.userid) { homecoming meteor.users.find({ _id: this.userid }, { fields: {'settings':1}}); } this.ready(); }); //client side meteor.subscribe('usersettings');

but not see anyway how can access published "usersettings" object on client side - missing ??

you can create field , set false/'', on each user create using accountsoncreateuser method.

accounts.oncreateuser(function(options, user) { //this function gets called each time user has been created on meteor.user collection if (options.profile) user.settings = ''; //this , example. homecoming user; })

now publish looks ok, in order work im utilize tracker.autorun function.

tracker.autorun(function(){ meteor.subscribe('usersettings'); })

why autorun? if don't phone call auto run here, subscription called 1 time when apps loads, , not when user documents.

take care of yours deny/allow permissions, check meteor:common mistakes post on profile editing section

also subscribe function have callback function. meteor.subscribe(name, [arg1, arg2...], [callbacks]), can this.

var myusersubscription = meteor.subscribe('usersettings',function(){ console.log("ok im here on client side") console.log("this user subscription ready " + myusersubscription.ready()) }) console.log("outside subscription why not? " + myusersubscription.ready();

about ready();

true if server has marked subscription ready. reactive info source.

collections meteor publish-subscribe

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -