How can I simulate "update" in a stub of method?

Hi.

I have a method that updates a collection and do something.

Meteor.methods
    aMethod: (collectionId, data) ->
        ACollection.update collectionId, $set: data: data
        doSomethingAboutACollection()
        return

(The above snippet is in CoffeeScript)
It works fine, but no early simulation of update.

I wonder that if I write the same stub for clients, the update will occur in multiple times.
Is my understanding right?

And how can I write the code that simulates update in clients and processes data as I want?

Your Meteor.methods must be on both server and client for the simulation to work. No clientside method, no stub.

You don’t have to worry at all about update occuring in multiple times. The only update that actually matters is the one on the server. The one on the client is only for the user’s convenience.

I was unaware you can do it with collectionId instead of {_id: collectionId). Can’t find it in Mongodb docs. Well, good to know.

Thank you, brajt-san!

So you mean that “update” method in a stub only updates local database?

And I have a next question.
I am also using observeChange.
In this case, when do observeChange related events occur?
When updating local database, or when updating server database?

  1. Yes, that’s why we call it a stub. It works only temporarily, until it gets replaced by the actual data from the server.

  2. No idea, as I don’t use observeChange.

Thank you!
I will try!