Will reactivity change the result of a res.forEach whilst executing?

Read a blog post about reactivity today ((https://www.discovermeteor.com/blog/reactivity-basics-meteors-magic-demystified/ Reactivity Basics: Meteor’s Magic Demystified )). As the cursor in collection.find() is reactive does it mean:

A) Whilst executing the res.forEach loop the result set (cursor) is updated to reflect the changes that happened on the collection?


B) The forEach loop will continue to be executed with the original result (cursor) until the last document is read, then and only then the reactivity is executed


C) something else


Can someone enlighten me? This is obviously very important for apps operating with multiple users working on the same collection. If A is true that would mean a res.forEach could be kept going continuously as long as new data is inserted into the collection.

I hope it’s B or C


1 Like

If you are using it within a reactive computation like Tracker.autorun() or a template helper, yes, it will update the result (synchronously and sequentially).

But if you are using it outside a reactive computation, like a normal function, a method, somewhere on the server etc, it will not rerun.

So it all depends on the context.

I am still thinking that Cursor is always reactive (ofc in reactive context like tracker, helper etc)
But .forEach and .map have special magic which will not recalculate new value for every document, but only for changed ones.
Instead of doing fetch and than doing .forEach or .map or whatever above resulted array which will recalculate everything again.

Sorry Robert, your comment is unclear to me. I’m currently using only .find() and not .find().fetch() (correction, double checked my code and I indeed use .find().fetch() in one instance).

Are you saying:

.find() = no recalculation in .forEach()


.find().fetch() = recalculation in .forEach()

Did I read you post correct?