Handle when data in collections changes

Hi there. How should I use Tracker.autorun to handle when array in my collection changes length? Thanks for help.

Can you be a bit more specific? The answer will depend on what exactly you are trying to accomplish. For instance, if the array is part of a document in a Minimongo collection and you are using that document in a Blaze template, you don’t need Tracker.autorun at all.

I need to watch the size of the array from my mongo collection on server side. When array’s size = 2 I need to call one function and when it has 20 elements - call another. How can I do it?

If you really want to use Tracker.autorun server side, take a look at peerlibrary:server-autorun.

Thanks, I will try it.

I wouldn’t recommend using an autorun for that. Use a collection hook instead. Search Fastosphere for collection hook.

I’m really curious about this. If you can share it, what’s the use case?

I’m using node.js proccess to change data in mongo. Collection hook fired only when data was changed from meteor as I can see.

Didn’t help for me. Probably I’m doing something wrong. Is there example or something?