String Type Size in MongoDB

I know that ObjectIDs are 12 bytes in MongoDB. And I know that numbers are 64 bit. But how do you know the size of a stored string

+5
source share
1 answer

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.

+5
source

Source: https://habr.com/ru/post/1208252/


All Articles