Get Started Free

More information about BSON document size

MongoDB stores documents as BSON (Binary JSON), a binary encoding of your JSON-like data. BSON is not the same size as the JSON text: each field carries a type byte and a length prefix, and values are stored in fixed binary widths. This tool measures that encoded size by serialising your document with MongoDB's official bson library — the same code path a driver uses to put a document on the wire.

Which formats you can paste

All three of the formats you're likely to have on your clipboard:

Shell types are all supported: ObjectId(), ISODate(), NumberInt(), NumberLong(), NumberDecimal(), Timestamp(), BinData(), UUID(), DBRef(), Code(), MinKey, MaxKey and regular expression literals such as /^ab/i. So are the conveniences the shell allows: unquoted field names, single-quoted strings, trailing commas and comments.

Why a plain integer has two possible sizes

A bare number such as 42 is the one genuinely ambiguous value in a pasted document. The drivers store an integer that fits in 32 bits as a 4-byte int32. mongosh does not: a number literal there is a JavaScript double, so the same field is stored as an 8-byte double. Four bytes per field sounds trivial until you paste a document with hundreds of numbers in it.

Use the toggle under the input to say which one you want. If you copied the document out of mongosh, pick double. If you're modelling what your application will write, pick int32. Values with an explicit type — NumberLong("42"), {"$numberInt": "42"} — are exact and ignore the setting entirely.

The 16 MB limit

A single BSON document cannot exceed 16 MB. Hit that ceiling and writes fail, so it's worth watching for documents with large arrays or embedded blobs. If you're approaching the limit, reference large sub-documents in a separate collection or store binary payloads in GridFS.

How BSON size is calculated

Reading the per-field breakdown

The breakdown lists every field with its full cost — type byte, field name and value — sorted largest first, so the field responsible for an oversized document is at the top. Nested documents and arrays expand, and the numbers add up exactly: the rows at any level sum to their parent. A document that's too large is nearly always one unbounded array or one embedded blob, and this is the fastest way to find out which.

Frequently asked questions

VisuaLeaf

Model documents that stay within limits using VisuaLeaf

VisuaLeaf's visual schema designer helps you spot unbounded arrays and oversized embeds before they become a problem, alongside a full MongoDB and SQL client with query builders and charts.

MongoDB & SQL in one client
Visual query & aggregation builders
Live visual schema diagrams
Charts, dashboards & query profiler
Connection manager for local, cloud & teams
Free Community Edition