I know that ObjectIDs
are 12-bytes in MongoDB. And I know that numbers
are 64-bit. But how do I find out the size of a saved string
The bson specification at http://bsonspec.org/spec.html is a good starting point.
In particular, it's important to realize that BSON does have integer types, including 32 bit integers which is even the default, despite the fact that JavaScript uses a 64 bit floating point numbers - MongoDB uses JavaScript a lot, but it's not written in JavaScript and has different types. The existence of true integers is quite important, otherwise a $inc
on a large number wouldn't work.
To answer your question: strings are stored as UTF-8 encoded strings with a zero terminator and a 32-bit length in front, plus the 1-byte type indicator and the element name, of course. Keep in mind that objects have additional overhead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With