Dynamically stripping objects from their fields in Meteor -


i have 2 collections, objects , parents:

objects = new meteor.collection('objects'); parents = new meteor.collection('parents'); 

the objects contain fields , refer parent object, example:

objects.insert({ name: "o1", parent: "p1", f1: "val1", f2: "val2", f3: "val3" }); objects.insert({ name: "o2", parent: "p2", f1: "val4", f2: "val5", f3: "val6" }); 

the parents define field can sent client, example:

parents.insert({ name: "p1", allowedfields: [ "name", "f1", "f2" ] }); parents.insert({ name: "p2", allowedfields: [ "name", "f1", "f3" ] }); 

i want publish/subscribe objects, receive them stripped of non-allowed fields.

according above example, i'm expecting following on client:

{ name: "o1", f1: "val1", f2: "val2" }); { name: "o2", f1: "val4", f3: "val6" }); 

how can efficiently?

context:

  • meteor
  • i typically have 100 parents , 1000 objects
  • i don't know in advance how many parents/objects have, , don't know allowed fields referred each parent

do following...

on server:

meteor.publish('objects', function(parentname) {     var parent = parents.findone({'name': parentname});     var allowedfields = {};     (var = 0; < parent.allowedfields; i++)         allowedfields[parent.allowedfields[i]] = 1;     return objects.find({ parent: parentid}, { fields: allowedfields }); }); 

on client:

parents.find({}).foreach(function(parent) {     meteor.subscribe('objects', parent.name); }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -