Working with arbitrary data
MongoDB utilizes BSON as the primary data format. It is a binary format that can store no or many key/value pairs in a single entity called document; for example, a sample JSON, {"hello":"world"}
, becomes \x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00
when encoded in BSON.
The main advantage of BSON over JSON is that it actually stores data, not just literals. For instance, if a long integer number needs to be a part of the document, it will not have to be converted programmatically from a literal to a number. It is also useful when a document needs to have some data bound to it. JSON will usually represent such data as base64-encoded bytes, but that is obviously not the most efficient way.
Mongoose schemas enable storing binary content in the BSON format via the SchemaTypes buffer. It can store binary content (image, ZIP archive, and so on) up to 16 MB. The reason behind the limitation to storage size is rather historical as a means...