Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Calculating Size of a Document via Query
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Charlie Mason  
View profile  
 More options Oct 5 2012, 4:30 pm
From: Charlie Mason <charlie.m...@gmail.com>
Date: Fri, 5 Oct 2012 13:30:41 -0700 (PDT)
Local: Fri, Oct 5 2012 4:30 pm
Subject: Calculating Size of a Document via Query

Hi All,

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.

Thanks,

Charlie M


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jenna deBoisblanc  
View profile  
 More options Oct 9 2012, 5:58 pm
From: Jenna deBoisblanc <jenna.deboisbl...@10gen.com>
Date: Tue, 9 Oct 2012 14:58:31 -0700 (PDT)
Local: Tues, Oct 9 2012 5:58 pm
Subject: Re: Calculating Size of a Document via Query

Hello Charlie,

To get the total size, you could add up the document sizes using $where or
Map Reduce and the method, Object.bsonsize(doc).
http://www.mongodb.org/display/DOCS/MapReduce
http://docs.mongodb.org/manual/reference/operator/where/

These solutions, however, rely on Javascript and may not be very efficient.
If you can restructure your documents, a better solution may be to store
each document's size with the document. The Java method encode() takes a
BSONObject and returns a byte array (http://api.mongodb.org/java/current/),
which you could use prior to insertion to calculate, and subsequently
store, doc size. The advantage of this strategy is that you can get total
size using the aggregation framework (included in v. 2.2), which is written
in C++ and may have much better performance:
http://docs.mongodb.org/manual/applications/aggregation/

Here is another link that you may find useful:
http://stackoverflow.com/questions/10885794/java-driver-equivalent-fo...

As for your second question about index size, you're correct- the size of
the index entry is approximately the key size plus some overhead.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »