javascript - Why does Meteor use EJSON and not BSON directly? - Stack Overflow

As I understand it, Node.js supports BSON (not sure if natively or with an npm package). Meteor however

As I understand it, Node.js supports BSON (not sure if natively or with an npm package). Meteor however invented a new flavor EJSON (Enhanced JSON), but I fail to see what advantages this brings and how it is better than using BSON directly.

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

As I understand it, Node.js supports BSON (not sure if natively or with an npm package). Meteor however invented a new flavor EJSON (Enhanced JSON), but I fail to see what advantages this brings and how it is better than using BSON directly.

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

Share asked May 20, 2014 at 8:44 StephanStephan 1,2798 silver badges17 bronze badges 3
  • Being curious, are you sure E in EJSON is short for Enhanced? – Peppe L-G Commented May 23, 2014 at 8:44
  • Nope, not sure. Probably it stands for Extended JSON rather than Enhanced, but the official docs never resolve the acronym... Since I am still missing some authoritative statement on the exact meaning of E I will leave the question like this for now. – Stephan Commented Apr 22, 2015 at 10:08
  • I couldn't find the answer neither, so I hoped you could settle it for me. Well, one year of waiting to a waste :'( But thanks! – Peppe L-G Commented Apr 22, 2015 at 13:05
Add a ment  | 

1 Answer 1

Reset to default 10

Well it is not as if BSON has gone away, it is still actually there. The Meteor MongoDB driver section is built on top of the native node driver for MongoDB and that of course uses BSON to actually talk to MongoDB, and there is no other way since that is the language that MongoDB speaks, so to say.

AFAIK, the point of EJSON is to maintain the same sort of "type fidelity" that is inherent in BSON by it's binary definition when translating to clients that only understand JavaScript, and therefore JSON. So primarily browsers.

So as part of Meteor's goal is to make the difference between client and server side code somewhat transparent, it needs a mechanism to maintain this "type fidelity", for Dates, ObjectId etc, when transferring data to and from client and server.

So the difference of EJSON and JSON being, the JSON produced includes special keys that identifies these "types" so they can be properly processed that way, especially when talking to the server process.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745045093a4608047.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信