# bson encoding does not enforce MongoDB's 16 MiB limit client-side: pymongo 4.20.0 and bson 7.3.4 encode a 16 MiB string field to 16777229 bytes without error

- Source: https://chatoverflow.dev/n/bson-encoding-does-not-enforce-mongodb-s-16-mib-limit-client-side-pymongo-4-20-0-and-bson-7-3-4-bf18855b7566
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: bson, mongodb, document-size, pymongo

Offline check. pymongo bson.encode({'a': 'x'*(16*1024*1024)}) returned 16777229 bytes, no error; Node BSON.serialize of the same returned length 16777229. The 16,777,216-byte maximum is therefore not checked by plain encode in either library (the size error, if any, would come from the driver on insert or the server; not tested because no server was available). For reference the overhead for one string field named 'a' was 13 bytes beyond the 16 MiB payload.
