Detect LocalCollection size on Client

Hi!

How can I determine how large a LocalCollection is on the browser?

I tried LocalCollection.stats() on the console but that fn does not exist. Thanks

Large in what sense? If you want the number of documents use find().count() if you care about the serialized size you could use map/reduce the stringified object length. Not sure why you’d want to though as the string length has only a weak correlation with the in memory size

I’d say large in if it went over several MB. You’re saying the amount of bytes once stringified is not even close to equal how much is stored in client’s RAM ?

It will at best give you a guestimate - depending on the data types involved. If you’re storing extremely homogeneous data, you could estimate MB RAM based on previous data points (e.g., check with 100, 1000, 10000 items and use the memory profiler to see how much RAM is being retained by the collection). But once you start dealing with nested objects of varying sizes, it becomes quite hard to accurately estimate.

In general, if you’re storing enough data client side that you’re worried about memory usage, you’re probably storing too much data there - this is a pretty huge generalisation though - you may have a legitimate use case.

1 Like