我想将一个集合发布给用户拥有的用户'
Meteor.publish('test', function(){ return questiondummy.find({'author':'Jaspermid'});
});
用
订阅它Meteor.subscribe("test");
不幸的是,这不起作用。我可以使用确切的用户名
在mongodb数据库中找到该集合{ "questionnumber" : 10, "user" : "Jaspermid", "timestamp" : 1407063133137, "answerarray" : [ "1", "2", "3", "4" ], "_id" : "fDcfnenhNsZNAmsze" }
1。有谁知道为什么我不能在客户端看到这个集合 2.如何以及在何处合并(Meteor.user()。用户名仅发布给当前用户?
提前谢谢
答案 0 :(得分:0)
find
的选择器应为{'user':'Jaspermid'}
,而不是{'author':'Jaspermid'}
。
使用{'user':'Jaspermid'}
{'user': Meteor.user().username}
醇>
修改强>
Oups,Meteor.user()
可用于“ Anywhere,但发布功能”。我的错误。
答案 1 :(得分:0)
您可以通过_id
从发布功能中访问当前用户的this.userId
。您可以使用它来查找用户名。
http://docs.meteor.com/#publish_userId
Meteor.publish('test', function(){
var user = Meteor.users.findOne(this.userId);
if (user)
return questiondummy.find({user: user.username});
this.ready();
});
this.ready()
告诉客户即使您没有发送任何数据(例如用户未登录时),订阅也已准备就绪。