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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With