【发布时间】:2016-08-20 10:48:55
【问题描述】:
我已经通过流星中的服务器代码创建了一个 mongoDB 集合:
//Server
Restaurants = new Mongo.Collection('restaurants')
if (Meteor.isServer) {
//This code only runs on the server
Meteor.publish('restaurants', function () {
return Restaurants.find();
});
}
每当数据库中的数据发生变化时,我都会尝试在客户端获取最新数据。
这是我的客户端代码:
//Client
Restaurants = new Mongo.Collection('restaurants');
var myData = "";
if (Meteor.isClient) {
Meteor.subscribe('restaurants');
myData = Restaurants.find();
};
谢谢!
【问题讨论】:
-
问题是什么?你读过流星指南吗?好像 Tracker 就是你所追求的。阅读它。
-
非常感谢 masterAM..works :)