6

I modified the leaderboard example to use two collections:

Players = new Meteor.Collection("players");
Tasks = new Meteor.Collection("tasks");

The Players collection has the 6 documents defined in the example.

> db.players.count()
6

The Tasks collection has 48,000 documents.

> db.tasks.count()
48000

As soon as I open the browser, Node jumps to 100% CPU and the client can't see any of the tasks records.

Players.find().count()
6
Tasks.find().count()
0

I tried defining query criteria but that only works on the server and doesn't help on the client.

Players.find({name:"Claude Shannon"}).count();
1
Tasks.find({tid:"t36254"}).count();
0

I'm guessing that 48,000 documents is too much to sync. That's causing Node to peg at 100% CPU and the client to throw errors like this: http://i.imgur.com/zPcHO.png.

How do I prevent syncing everything and only retrieve specific documents from the collection?

4

1 に答える 1

18

すべてのコレクションをクライアントに公開するMeteorの自動公開は非常に印象的で、処理が高速になりますが、Railsのスキャフォールディング機能のようなもので、実際のアプリにはあまり役立ちません。学習とプロトタイピングに使用します。

デフォルトでは、Meteorはコレクション内のすべてのドキュメントを接続されている各クライアントに自動的に公開します。この動作をオフにするには、パッケージを削除します。

$meteorは自動公開を削除します

次に、必要な制御を提供する手動のパブリッシュおよびサブスクライブ機能の使用方法を学習します:http: //docs.meteor.com/#publishandsubscribe

于 2012-04-27T11:19:31.737 に答える