Change data in all clients, while no method is created on the client

As I keep in mind, in order for us to have a real-time site and make changes to the database for all users at the same time,
Methods must also be entered in the client and defined in the client.

I did not enter these methods in the client, but I still see that the changes are done in real time for all users.
For example, if I create a post in one browser, it will be created quickly in another browser.
While the post creation method is not entered in the client.

Currently, when a change is made to the database in a browser, the change is sent to all clients.
I do not want the whole software to have this function. Because I think the bigger the software, the lower its performance because it takes more resources from the server.

“make changes to the database for all users at the same time, Methods must also be entered in the client and defined in the client” - this is a wrong statement.
Details are here: Methods | Meteor API Docs.
Meteor can use Optimistic UI. You would get the update on your client but not on the other clients.
That can only happen with techs like pub/sub, Streams. etc.

I believe your issue is related to a pub/sub. You could use a Meteor plugin for Chrome and see what subscriptions activate when you do various things. I would assume you already removed unsecure and autopublish packages.

Please remove the insecure package: meteor remove insecure

1 Like

@minhna @paulishca

hi ,
I made a small sample, please run this very small repository and open the application in two browsers.
In this example, when you create a new link, both your ui is rebuilt and the new link is displayed to you in real time, and also the ui of the other clients is rebuilt, and in fact the new link is displayed to them immediately.

This is while I did not enter the method that creates the new link in the client at all.
And normally my ui should not be rebuilt and no new data should be sent to other clients.

@paulishca @minhna
This is while I did not enter the method that creates the new link in the client at all

I definitely deleted this, please look at the sample repo

Hey, I’m not sure if I got your question right because I was not able to open your repository but the fact that you haven’t imported the Meteor methods on the client side it’s not related to having real time updates on different browsers.

When you import methods on the client what you have is optimistic UI, meaning that they will be simulated on the client and each user will get a quicker response because your logic will run on the client using minimongo before running on the server. When the method finish running on the server you get the real result of the operation.

Real time updates are the default way that Meteor works when you use publications and subscriptions.


Sorry, I just made it public and you can see it

How to prevent all data from being real-time.
I just need part of the site to be real time.
I think if all the site with all its details is real time, it will be a heavy burden on the server.
And this time with the addition of users, even more

There should be a setting for each publish , which indicates whether it is real-time or not

You can do it by your self. I know 2 opitons:

  1. Use methods to load your data. I prefer this option.
  2. Use Pub/Sub to load your data but you need to rewrite your publish function a little.
    Instead of return the cursor, you call the function this.added to send data to client and this.ready() at the end.

for example:

Meteor.publish("links.all", function () {
  const links = Links.find(); => {
    this.added('links', link._id, link);

On the client, you call Meteor.subscribe function normally. But remember now your data will not be updated automatically.

1 Like

@minhna How do I do this with methods?
And why is it better with methods?

I don’t say it’s better in every cases.
For example when you go to a page, there is a react component there and in that component I call a method, it returns data I need. I don’t have ty select them from the mini mongo, I don’t care if I need to remove them after the component got unmounted.
But when I needed the data sits there for awhile. I would use pub/sub or I would insert them in local collections directly.
It depends on how your app works. There is no best option for all cases.

I just created a quick sample on how to use methods for fetching data.
I usually follow this way when I don’t need real-time updates.

I tried to change your code as little as possible and created this PR:

1 Like

@fredmaiaarantes @minhna
Tank you all


@fredmaiaarantes @storyteller
The problem with this method is that it is not compatible with ssr.
The react-router-ssr package works on a pub / sub basis.
As a result, no ssr is provided on pages where data is captured by methods.