I'm publishing a cursor that outputs just one document inside of it:
Meteor.publish ( 'test', function () {
return MyCollection.find ( 'DocumentMongoDBID' );
}
And I'm subscribing to it from the router (using iron router):
Router.route ( '/thepage', {
...
subscriptions: function () {
this.subscribe ( 'test' ).wait ();
}
}
I want to redirect the user to another page if the document gets deleted, hence if the cursor is empty.
How can I get a function invoked when this happens so that I can redirect the user? All the template's helpers that rely on that subscription gets called, but I'd prefer to have another function called before of them, that will eventually redirect the user.
Maybe try using LocalCursor.observeChanges
on the client-side ?
Meteor.startup(() => {
MyCollection.find('DocumentMongoDBID').observeChanges({
removed(){
// redirect the user
Router.go(...);
}
});
});