I would like to calculate the size of particular documents in a mongo
collection. Since the collection will contain many documents created by
different users I would like to know how large each users documents are. I
would ideally like to avoid having a collection per user, as ultimately it
may be shared as a few users may exceed the capacity of one mongod node.
Ideally I would like to calculate the total of all docs that match a
particular query. I would like this to be as efficient as possible but it
could be done as a batch job if it might to a few mins to perform.
I appreciated that the size on disk will be larger because of padding and
compaction, its the size of the data itself I am after.
If it can't be done at the DB level can I do it when I write to the
collection via the Java Driver and Morphia? Is there some java code that I
can use with Morphia to get the size of the documents data?
I would also like to calculate the size of any indexes on fields in a
document. Is there any way to estimate how much space they will consume. Is
it just a case of storing the fields value a second time, plus some
constant overhead presumably?
It doesn't matter if any of the these calculations are off by a byte or
two, I just want to be able to calculate rough levels of usage.