Reputation: 69
I want to understand how MongoDB query works.
Please correct me if i'm wrong, but MongoDB use the serialization protocol BSON to save the data inside real document called collection. By real i mean a file and not in memory.
To search for the data fast MongoDB use B-tree for any query.
Does the BSON data that is saved inside a document get first deserialized and then inserted inside B-tree to be indexed and accessible from memory?
If not how then?
Upvotes: 0
Views: 139
Reputation: 14520
As I understand it, BSON is the data storage format used by the server. This means documents are stored on disk in BSON format as well as in memory on the server side.
Indexes naturally deal with individual field values, not with complete documents. Therefore BSON is not applicable to indexes. I don't know whether indexes store individual values in the same format that BSON does (for example timestamps, uuids, arrays).
Does the BSON data that is saved inside a document get first deserialized and then inserted inside B-tree to be indexed and accessible from memory?
No deserialization is necessary on the server side because the server is able to either directly access the data in BSON documents or natively iterate BSON documents. See http://mongoc.org/libbson/current/parsing.html for how this might be accomplished.
Most drivers, by virtue of being implemented in languages other than C, deserialize the entire BSON document into their language-native data structure and then access and iterate that data structure.
Upvotes: 0