Reputation: 1293
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: https://i.sstatic.net/F4dpX.png.
How do I prevent syncing everything and only retrieve specific documents from the collection?
Upvotes: 6
Views: 2474
Reputation: 1074
The autopublish of Meteor, which publishes all of your collections to the client, is very impressive and makes things work fast, but it's kind of like Rails scaffolding functionality - not very useful for real apps - it's for learning and prototyping.
By default, Meteor automatically publishes every document in your collection to each connected client. To turn this behavior off, remove the package:
$ meteor remove autopublish
Then, learn to use the manual publish and subscribe functions, which offers you the control you need: http://docs.meteor.com/#publishandsubscribe
Upvotes: 18