I working with meteor to create an app. In meteor Meteor.methods and Meteor.publish are used to perform database operation.I know use of Meteor methods and pub/sub
My question is there any criteria when to use Meteor.methods and when Meteor.publish?.
Meteor.publish
is the pub part of pub-sub obviously. As data gets added or changed that is being published the server will automatically send it over to any client that has subscribed to that publication.
Meteor.call
is request-response. You make a request, you get a response. Party's over. If data changes on the server that the method uses your client won't know about it until you make another call.
Meteor Publish Subscribe is a way to allow access (read and write) to clients, and to keep all clients and server updated with the latest data. Meteor Publish/Subscribe has only to do with meteor database.
Meteor methods is much more, it can be used for various uses, such as making calls to API's (HTTP calls to your REST API's), etc. (P.S. It is recommended to make these calls from server side for security reasons).
Also, when fetching data by calling Meteor Method (using Meteor.call), you can do some kind of verification or validation on server side before fetching or returning the data.
And yes, Michel Floyd's answer is another great point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With