【问题标题】:Autopublish removed but why can I still retrieve data from db?自动发布已删除,但为什么我仍然可以从数据库中检索数据?
【发布时间】:2014-04-24 15:02:52
【问题描述】:

我有一个使用“角色”包的简单 Meteor/MongoDB 项目,我将数据从数据库选择到客户端。角色包似乎工作正常,浏览器根据登录者显示正确的数据,就像它应该做的那样。然后,当在我的应用程序目录内的终端中运行“流星删除自动发布”时,我会得到“自动发布删除”,就像它应该的那样。我仍然可以像以前一样从服务器检索数据(!?)

我有来自 client/client.js 的所有数据库调用。

server/server.js 什么都不做(我确实有发布/订阅代码,但现在取消注释),主目录中的公共 js 文件也是如此。

这怎么可能?我是否可能以某种方式从 minimongo 检索数据?即使我认为在这种情况下不重要,我也删除了不安全(?)提前谢谢。

编辑:这是代码:

client.js:

//when uncomment the subscribe's you should not get access to the server/db, but 'data' that holds all the inlogg info still shows. The 'movies' on the other hand doesn't, just like it shouldn't. 

//Meteor.subscribe('data'); 

//Meteor.subscribe('movies');

/*############# Get User Data ###############*/

Template.userLoggedIn.id = function () { 
   return Meteor.userId();
};

Template.userLoggedIn.email = function () {
   var email = Meteor.users.findOne({_id: Meteor.userId()});
   return email.emails[0].address;
};

Template.userLoggedIn.profile = function () { 
   var profile = Meteor.users.findOne({_id: Meteor.userId()});
   return profile.profile.name;
};

Template.userLoggedIn.role = function () { 
   var role = Meteor.users.findOne({_id: Meteor.userId()});
   return role.roles[0];
};

/*#############  ###############*/

Template.movies.movies = function() {
   var movies = Movies.find().fetch();
  return movies;
}

server.js:

Meteor.publish('data', function () {
      return Meteor.users.find();
});

Meteor.publish('movies', function() {
      return Movies.find();
});

【问题讨论】:

  • 删除 autopublish 将重新加载您的应用程序,然后清除您的 minimongo 数据。不看代码真的很难回答这个问题。 meteor list --using 显示什么?您可能还需要仔细检查这些发布功能是否实际上已被注释掉。
  • 感谢您的回答。这是终端列出的内容:standard-app-packages accounts-password roles accounts-ui

标签: mongodb meteor database


【解决方案1】:

感谢您提供代码 - 我知道这可能会造成混淆。应该写文档的users 部分来明确说明这一点,但发生的情况是当前用户始终被发布。因此,即使您没有为用户编写发布功能(或者您的订阅已被注释掉),您也应该期望在客户端上看到当前用户。因为您的模板代码只查找 Meteor.userId(),所以我希望它仍然可以工作。

假设您在数据库中有其他用户,您可以通过在浏览器控制台中运行:Meteor.users.find().count() 来快速检查他们是否未发布。如果它返回1,那么您只是在发布当前用户(或0,如果您已注销)。

【讨论】:

  • 好的,我尝试发布其他用户,但正如您所说,只发布当前用户。非常感谢。
  • 太棒了!我很高兴我们弄明白了。如果您觉得这个答案有帮助,请考虑accepting it
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-02
  • 1970-01-01
  • 1970-01-01
  • 2016-05-23
相关资源
最近更新 更多