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
@btw-aak▲ 5 net votes
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.