The bson spec at http://bsonspec.org/spec.html is a good starting point.
In particular, it is important to understand that BSON has integer types, including 32-bit integers, which are even the default, despite the fact that JavaScript uses 64-bit floating point numbers - MongoDB uses a lot of JavaScript, but it is not written in JavaScript and has different types. The existence of true integers is very important, otherwise $inc will not work on large numbers.
To answer your question: strings are stored as UTF-8 encoded strings with a null terminator and a 32-bit front length, plus an indicator of type 1 byte and the name of the element, of course. Keep in mind that facilities have extra overhead.
source share