On server collection update


#1

What is the best way to do this in Meteor?

On client-side insert, is there an event I can I listen for on the server for when that specific new doc is available on the server? I want to kick off another server-side process, using the contents of that doc, only when that new doc is available on the server.

I want to preserve updating the client first because my user temporarily be offline.

Thanks,
Don


#2

Take a look at: https://github.com/matb33/meteor-collection-hooks


#3

Looks promising. Thank you. :smile:

I can’t really tell from their docs, what “after” really means. Is it after client-side insert or after meteor reactively updates (after latency) the server-side?

What code runs on the client and what runs on the server? I will need to know the id of the document inserted on client, so I can grab that same document on the server.


#4

Do I just drop this on the server and the hook just works for all inserts into test?

test.after.insert(function (userId, doc) {
// ...
});

#5

I wrapped this in isServer and the hooks fires after the client insert. Very nice!

Thank you for the help.

Don


#6

Hah, I was just about to answer your questions, but it looks as though you’ve answered them yourself! :smile:


#7

Collection hooks is awesome for when you’re allowing clients to modify the DB directly.
Haven’t found them too useful when I am using calls & methods though.