Clear local Meteor Mongo collection on user logout

1.7k Views Asked by At

I am starting to heavily use local minimongo collection

LocalItems = new Meteor.Collection null

SomeOtherItems = new Meteor.Collection null

and i'd like to be able to empty all of these local collections when a user logs out; any suggestions?

1

There are 1 best solutions below

2
On

Try this, I assume from your code that you're using coffeescript. If not, let me know and I will rewrite it as javascript:

Meteor.logout ->
  LocalItems.remove {}
  SomeOtherItems.remove {}

If you're using accounts-ui and don't call the logout function directly, I think you'll need to do something like this:

Deps.autorun ->
  unless Meteor.user()
    LocalItems.remove {}
    SomeOtherItems.remove {}

Or you could do this:

Template.loginButtons.events
  "click #login-buttons-logout": ->
    LocalItems.remove {}
    SomeOtherItems.remove {}