Why is Meteor using EJSON and not BSON directly?

As I understand it, Node.js supports BSON (not sure if it is natively or with the npm package). However, Meteor invented the new fragrance EJSON (Enhanced JSON), but I don’t see what advantages it brings and how it is better than using BSON directly.

Does anyone know what are the advantages of EJSON over BSON or what are the reasons why EJSON is required when JSON and BSON are available?

+6
source share
1 answer

Well, it’s not as if BSON is gone, it is still actually there. The Meteor MongoDB driver section is built on top of the native node driver for MongoDB and, of course, uses BSON to actually communicate with MongoDB and there is no other way, since this is the language MongoDB speaks, so to speak.

AFAIK, the EJSON point is to maintain the same type of "type validity" that BSON has inherently means when it is binary defined when translating to clients that only understand JavaScript, and therefore JSON. So first of all, browsers.

Thus, as part of Meteor’s goal to make the difference between client and server codes somewhat transparent, it needs a mechanism to maintain this “type fidelity” for Dates , ObjectId , etc. when transferring data from both the client and server.

Thus, the difference between EJSON and JSON produced by JSON includes special keys that identify these “types” so that they can be correctly processed in this way, especially when talking to a server process.

+10
source

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


All Articles