【发布时间】:2016-08-30 19:26:57
【问题描述】:
对于同一个集合的不同视图,我有多个订阅和发布。其中一个视图用于返回对 Mongo 集合的文本搜索,而其他视图则返回整个集合。
我的问题是当我尝试在客户端查看结果时,我不确定如何指定使用搜索结果订阅。目前,我的客户端视图显示的是整个集合,而不是受限的搜索结果。如何指定应使用哪个订阅?还是我误解了发布/订阅模型?可能我应该只使用一个订阅?任何意见表示赞赏!
// Server side publication
Meteor.publish("search", function(searchValue){
if (!searchValue) {
console.log("there is no search value");
return remoteData.find({});
}
console.log("there is a search value and it is " + searchValue);
return remoteData.find({$text:{$search: searchValue}});
});
Meteor.publish("allData", function (){
return remoteData.find();
});
// Client Side subscription
var searchSubscription = Meteor.subscribe("search", searchQuery);
var allDataSubscription = Meteor.subscribe("allData");
// inside React Component
// this returns everything, so I think it's using the allDataSubscription
filteredData() {
return (
remoteData.find({}).fetch();
)
}
【问题讨论】:
-
如果订阅了所有数据,那么所有数据都将在 minimongo 中可用。因此,可以在本地进行搜索。
-
问题是 minimongo 目前不支持 $text,据我所知,解决这个问题的唯一方法是在服务器端进行 $text 搜索