[SERVER-12984] Real document size in collection Created: 01/Mar/14 Updated: 18/Sep/21 Resolved: 18/Mar/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Diagnostics, Shell, Tools |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Jan Botorek | Assignee: | Stennie Steneker (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
Hello, I am not able to find out the real size of document stored in mongo collections. I googled, that document size may be obtained by two methods: I have a really simple document with this structure: By simle computation, the overall size should be more than 5 MB. I am really confused. Is there any way how to reliable find out size of the particular document? Are my steps performed so far absolutely wrong? Thank you for your support, any help will be appreciated. |
| Comments |
| Comment by Stennie Steneker (Inactive) [ 18/Sep/21 ] | |
|
Per earlier comments on this issue you can use something like Object.bsonsize() in the MongoDB shell or the equivalent in your MongoDB driver. However, if your documents are likely to approach the maximum document size limit you may be using a schema design anti-pattern like Massive Arrays. I highly recommend reviewing the articles in these two schema design series: There is also a free online course at MongoDB University: M320: Data Modeling. Lastly: please note that the SERVER project is for reporting bugs and potential improvements for the MongoDB server. For general discussion please start a new topic in the MongoDB Developer Community Forums. Regards, | |
| Comment by Santosh Kumar Aitha [ 14/Sep/21 ] | |
|
Hi Stennie, what is the best way to find the document size even before inserting into mongodb to prevent " document too large" error? | |
| Comment by Jan Botorek [ 03/Mar/14 ] | |
|
Hello, thank you a lot for your help! Yes, now the result seems good: >Object.bsonsize(db.test.findOne( {test:"test"})) It did not occur to me that I queried cursor instead of the real document object. | |
| Comment by Stennie Steneker (Inactive) [ 03/Mar/14 ] | |
|
Hi Jan, In your bsonsize() example you are measuring the size of a find(), which returns a cursor rather than a document. To find the size of a single document you should instead be using a findOne():
Can you confirm this shows the expected document size? Thanks, | |
| Comment by Jan Botorek [ 03/Mar/14 ] | |
|
Hello, 1) Create document: { test:"test", ids:[ "1111111111", "2222222222", "3333333333", ... ] }There is 990000 randomly generated strings representing virtual ID. Every id is composed from 10 characters. 2) Insert the document into the database:
3.a) db.test.stats(): ,
3.b) Object.bsonsize(db.test.find( {test:"test"})) Is there any other way how to find the real size of stored documents? Thank you for your support | |
| Comment by Daniel Pasette (Inactive) [ 03/Mar/14 ] | |
|
can you describe the exact commands you are running and run the collection stats command? |