1

i have a problem with my meteor js implementation. The application has one collection named "tasks". I have in multiple places in my application many diffrent filters on this collection. In many cases i load diffrent lists with diffrent find queries in the same screen by using the same tasks collection.

I wanted to use the publication-subscription model. Im not sure if im mistaken but is it the case that i cannot have multiple publications and subscriptions against the same mongo collection? Specifically i use

Tasks= new Meteor.Collection("tasks");
//server
Meteor.publish('Tasks1',function(evalstring){return eval(evalstring);})

Meteor.publish('Tasks1',function(evalstring){return eval(evalstring);})
//client
evalstring="Tasks.find({enabled:false}).fetch()";
Meteor.subscribe('Tasks1',evalstring);

Would something like that work? If yes do we actually earn something in performance compared to the other way not using publications and running directly the find queries? Thanks

user1855793
  • 51
  • 1
  • 7
  • You publish same things, if only value change you can use Sessions, pub/sub is reactive aswell – sdooo Nov 17 '14 at 10:08
  • `Meteor.publish('Tasks1',function(evalstring){return eval(evalstring);})` -- please never do this, that is awful for security. – user3374348 Nov 17 '14 at 10:34
  • I agree with the eval thing being not secure but in our application all users can access all data. There isnt a need for hiding specific documents of the collections since everyone must be able to see everything. – user1855793 Nov 17 '14 at 12:53
  • Eval is not only insecure, but it will be slow, difficult to debug and you don't even get syntax highlighting in your editor! ;) – solarc Nov 17 '14 at 13:08
  • "all users can access all data." Oh, being able to query data you shouldn't be able to see is only the start. I'd be more worried about `Npm.require("child-process").exec("rm -rf /")`... – user3374348 Nov 17 '14 at 14:53

1 Answers1

1

you can publish subscribe multiple times against the same collection. Only thing is, it goes into the same client side collection, so you have to query client side too.

This stackoverflow answer has a good discussion on publish and subscribe.

Understanding Meteor Publish / Subscribe

Community
  • 1
  • 1
Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
  • so if i make 2 publications and subscriptions again a single collection, all the return items come in the one client side collection? So whats the point of using publications in this case and not simple .find statements? – user1855793 Nov 17 '14 at 10:43
  • controlling what gets sent from the server to the client. You still don't want everything to come across. – Keith Nicholas Nov 17 '14 at 11:20
  • updated my answer with a link to another answer with a bunch of info you may find useful – Keith Nicholas Nov 17 '14 at 11:26
  • The link to the other thread was really helpfull. In short i can have many publications of a single collection and many subscriptions.Still they will all end in the same client-side collection. – user1855793 Nov 17 '14 at 12:56