Why use js-bson instead of serving JSON?

My web API has been serving binary data (BSON) to a native client. This approach seems efficient since the web API receives the raw BSON from MongoDB, and forwards it to the native client while the data remains in binary form along the way. Now we’re adding a web client. While I found the https://github.com/mongodb/js-bson library, I’ve read that BSON is less efficient than JSON in the browser. So why should I use js-bson rather than have my web API serve JSON instead of BSON?

The data in a MongoDB database is stored as BSON data types. The driver (e.g., Pyhton language, NodeJS platform, etc., drivers) converts the different data types used in the applications to BSON types and vice-versa.

The driver software lets the application use the BSON data as its JSON representation - see MongoDB Extended JSON (v2).

Hi @Prasad_Saya, how are you? That’s interesting that you consider js-bson as a driver – I hadn’t thought about it that way. Please continue your train of thought and answer my question. That is, why should I bother with js-bson when BSON is less efficient than JSON in the browser?


I dont think BSON is meant to be used with a browser. And, I dont think js-bson as a driver.

You can tell about a scenario (sample data / field, perhaps) about what is it you are trying to do with the help an example, using this BSON / JSON / JS-BSON.