尽管选择器键为空,但发布 returns 数据中的 Meteor find()
Meteor find() in publish returns data despite empty selector key
我正在创建允许人们协作的应用程序,因此我创建了 groups
可以分配给人们的应用程序。在服务器上,为了最大限度地减少客户端开销和安全性,我只 publishing
与他们的组相关的数据。我的代码:
Meteor.publish('lists', function() {
var user = Meteor.users.findOne(this.userId);
return Lists.find({group: user.profile.group});
});
我获取用户对象并根据该用户的 group
过滤发布的内容。实际上,他们的 profile
中应该有一个 group
ID。但是在测试期间,我创建了没有 group
的用户。我还创建了没有 group
的 lists
。
当我对我的测试用例 console.log user.profile.group
时,我按预期看到了 undefined
。问题是,我的带有未定义选择器值的 .find()
查询以某种方式 returning 所有 没有 的文档一个group
。就像 Mongo 告诉我“好吧,你没有给我们一个定义的组,所以这里是所有根本没有组参数的列表!”
我做错了什么?我认为 .find({selector-key: selector-value})
只有 return 一个游标,如果它找到匹配选择器 key/value 的数据?
防止退化条件:
Meteor.publish('lists', function() {
var user = Meteor.users.findOne(this.userId);
if ( user && user.profile && user.profile.group ) return Lists.find({group: user.profile.group});
this.ready();
});
我正在创建允许人们协作的应用程序,因此我创建了 groups
可以分配给人们的应用程序。在服务器上,为了最大限度地减少客户端开销和安全性,我只 publishing
与他们的组相关的数据。我的代码:
Meteor.publish('lists', function() {
var user = Meteor.users.findOne(this.userId);
return Lists.find({group: user.profile.group});
});
我获取用户对象并根据该用户的 group
过滤发布的内容。实际上,他们的 profile
中应该有一个 group
ID。但是在测试期间,我创建了没有 group
的用户。我还创建了没有 group
的 lists
。
当我对我的测试用例 console.log user.profile.group
时,我按预期看到了 undefined
。问题是,我的带有未定义选择器值的 .find()
查询以某种方式 returning 所有 没有 的文档一个group
。就像 Mongo 告诉我“好吧,你没有给我们一个定义的组,所以这里是所有根本没有组参数的列表!”
我做错了什么?我认为 .find({selector-key: selector-value})
只有 return 一个游标,如果它找到匹配选择器 key/value 的数据?
防止退化条件:
Meteor.publish('lists', function() {
var user = Meteor.users.findOne(this.userId);
if ( user && user.profile && user.profile.group ) return Lists.find({group: user.profile.group});
this.ready();
});