Subscription.stop not deleting records from client db (newbie Q.)


#1

I have a collection, times, the publish for which is filtered by eventId:

Meteor.publish("times", function (eventId) {
  return Times.find({
    eventId: eventId
  });
});

On the client, in the console, if I subscribe:

timesSub = Meteor.subscribe("times", "event1");

I get the three times for event1:

Times.find().fetch()
Array [ Object, Object, Object ]

So far so good.

However, if I stop the subscription:

timesSub.stop

the data is still there:

Times.find().fetch()
Array [ Object, Object, Object ]

And if a resubscribe with a different event (which has 4 times):

timesSub = Meteor.subscribe("times", "event2");

I get the data from both subscriptions:

Times.find().fetch()
Array [ Object, Object, Object, Object, Object, Object, Object ]

What am I missing? Thanks!


#2

EDIT: As pointed out below this is wrong.

Wrong: I don’t think you’re missing anything. Stopping a publication doesn’t delete records from the client side database.
You can subscribe multiple times to a publication with different params too.


#3

Oh, okay, I understood from the docs that it should. Let me ask the question a different way then:

How do I have Times only contain the times for the event passed in the method call, if that event changes?

(Another example might be a messaging app where the user can change channels, and only messages for the current chanel are displayed).

Thanks!


#4

There is a known issue in which “old” documents persist in a subscription - although this is normally only briefly. A somewhat hacky workaround is to use the same filter in the client find that you use in the publication.


#5

Are you shure? I gues you should read docs more carefully


#6

Thanks Rob for the suggestion, but that bug that is for a slightly more complex issue than mine.

It turns out it was a simply typo on my part - I was calling timesSub.stop instead of timesSub.stop(), so the subscription wasn’t actually being stopped. Rookie mistake.

With timesSub.stop() it works as expected.


#7

@mrzafod - that’s not very polite.


#8

My Typo is correct, but I am having a similar issue. It could be the Bug @robfallows mentions.

When I do collection.stop(), it clears up only the last subscription.

For sake of simplicity let’s say we have:

 subscribe("CCinfo", custId1);
 subscribe("CCinfo", custId2);
 subscribe("CCinfo", custId3);

 Cards.find()  on browser console will result in:
 Object    Object    Object

 CCinfo.stop()
 Cards.find()  on browser console will result in:
 Object    Object

No matter how many times run CCinfo.stop() those two first objects are never cleared.

EDIT: Sorry, I got confused trying to simplify. Corrected the above Cards.find() command.


#9

What is the type of CCinfo? Is it a Collection or SubscribtionHandler? Note, you could call stop for subscribtion only. Anyway if your example is correct I gues that you have 3 active subscriptions at one moment and then stop just last one.


#10

My CCInfo is:

CCInfo = Meteor.subscribe('Cards', GuestId);

I guess this is what you call “Subscription Handler”, right?

I tried

 Cards.stop()

But it gives me TypeError: undefined is not a function (evaluating 'Cards.stop()')