Quickly See Collection Sizes in Meteor

by Bruce Hubbard

Have a Meteor app that is loading slowly? You might want to look at how much data is being pushed down to the browser. If you’re being too generic with your publications or not paging or limiting data then you might be loading way too much. Here is a quick little snippet that I use anytime I’m looking at a performance problem in a Meteor app to see what collections are on a page and how many objects are being loaded:

var m = Meteor.connection._mongo_livedata_collections; for(var c in m) { var count = m[c].find().count(); if(count) { console.log(m[c].name + ": " + count);} }

If you run that snippet in a Chrome console (while on a Meteor app) you’ll get some output that looks like this:

users: 1
meteor_autoupdate_clientVersions: 4
beacons: 1950
company: 1
locations: 1

Reading that output you’ll see that I have 4 collections (any collections that start with meteor_ are typically internal to Meteor). On my page I have 1 User object, 1 Company object, 1 Location object and 1,950 Beacon objects that are being loaded on this page. So if the page were loading slowly I might want to look at limiting (or paging) the Beacon objects that are being sent to the page in my publication (1,950 is a ton of objects to wait on!). Hope this helps someone! Meteor rocks!

Share Share on Twitter Share on Facebook Share on LinkedIn

How Can We Help?

Reaching out doesn’t mean you’re ready to start a project, but we’d love to learn more about the challenge you’re facing, answer any questions, and see if we might be a good fit for working together.

Contact Us