peerlibrary/meteor-server-autorun

finds and findOnes don't work right?

Closed this issue · 5 comments

rclai commented

I tried doing this:

Tracker.autorun(function () {
  console.log('there are', Test.find().count(), 'test items')
});

While I inserted items into the Test collection in the Meteor shell, but the console.log didn't re-log again.

mitar commented

They work for local collections (Minimongo), but server-side cursor for MongoDB are not reactive by itself.

There is an idea to make them so with a package, but it is not yet there.

As a workaround you can make an observe which copies into a local collection from MongoDB, and then use queries on that local collection. For some cases it works well. :-)

rclai commented

Oh interesting.. haha.

aramk commented

I had the same issue and used cursor.observe() instead of Tracker. I have a wrapper in my library so I can handle all changes with a single callback:

Collections.observe Events.getCollection(), onEventChange
Collections.observe UserEvents.getCollection(), onEventChange

ReactiveVar still triggers changes in Tracker.autorun() with this library though.

mitar commented

In meantime we developed reactive-mongo package which provides reactive server-side MongoDB queries, and also reactive-publish which provides full server-side reactive publish endpoints.

aramk commented

Very handy!