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 ...
Get RESTful Web API Design with Node.js - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.