サーバーで流星コレクションを定義し、流星が提供するメソッドのいずれにも属さずにクライアントでそれらにアクセスしようとすると、クライアントでrendered, events, created, helpers ...
メソッドMeteor collection not defined
を再定義しようとすると、Meteor collection already exists
. Meteor.startup()
カスタムメイドのコレクションを関数で参照することで、これを回避できます。サーバーで定義したコレクションをクライアントで参照するにはどうすればよいですか。流星のドキュメントではMeteor.Collection()
、宣言する前でも の 2 つのインスタンスを作成して購読することができます。
// okay to subscribe (and possibly receive data) before declaring
// the client collection that will hold it. assume "allplayers"
// publishes data from **server's "players" collection.**
Meteor.subscribe("allplayers");
...
// client queues incoming players records until ...
...
Players = new Meteor.Collection("players");