【问题标题】:Clear local Meteor Mongo collection on user logout在用户注销时清除本地 Meteor Mongo 集合
【发布时间】:2013-12-17 07:12:28
【问题描述】:

我开始大量使用本地 minimongo 集合

LocalItems = new Meteor.Collection null

SomeOtherItems = new Meteor.Collection null

并且我希望能够在用户注销时清空所有这些本地集合; 有什么建议吗?

【问题讨论】:

标签: meteor client minimongo


【解决方案1】:

试试这个,我从你的代码中假设你正在使用咖啡脚本。如果没有,请告诉我,我会将其重写为 javascript:

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

如果你使用accounts-ui并且不直接调用logout函数,我认为你需要做这样的事情:

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

或者你可以这样做:

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

【讨论】:

  • 您收到此错误:未捕获的错误:不允许。不受信任的代码只能通过 ID 删除文档。 [403]跨度>
  • 您不想真正从集合中删除它们,只是从本地副本中删除。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-11
  • 2020-09-05
  • 2019-06-10
  • 2017-02-16
相关资源
最近更新 更多