删除了自动发布,但为什么我仍然可以从数据库中检索数据?

时间:2014-04-24 15:02:53

标签: mongodb meteor database

我有一个简单的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();
});

1 个答案:

答案 0 :(得分:1)

感谢您提供代码 - 我看到这可能会令人困惑。应该编写文档的users部分以明确说明这一点,但发生的是当前用户始终发布。因此,即使您没有为用户编写发布功能(或者您的订阅已注释掉),您也应该期望在客户端上看到当前用户。由于您的模板代码仅查找Meteor.userId(),因此我希望它仍可用。

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