peerlibrary / meteor-server-autorun

Server-side Tracker.autorun
https://atmospherejs.com/peerlibrary/server-autorun
MIT License
36 stars 7 forks source link

finds and findOnes don't work right? #7

Closed rclai closed 9 years ago

rclai commented 9 years ago

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 9 years ago

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 9 years ago

Oh interesting.. haha.

aramk commented 9 years ago

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 9 years ago

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 9 years ago

Very handy!