原文:https://www.e-learn.cn/content/qita/1999197

-------------------------------------------------------------

BSON

https://baike.baidu.com/item/BSON

概念

编辑

BSON()是一种类json的一种二进制形式的存储格式,简称Binary JSON,它和JSON一样,支持内嵌的文档对象和数组对象,但是BSON有JSON没有的一些数据类型,如Date和BinData类型。
BSON可以做为网络数据交换的一种存储形式,这个有点类似于Google的Protocol Buffer,但是BSON是一种schema-less的存储形式,它的优点是灵活性高,但它的缺点是空间利用率不是很理想,
BSON有三个特点:轻量性、可遍历性、高效性
{"hello":"world"} 这是一个BSON的例子,其中"hello"是key name,它一般是cstring类型,字节表示是cstring::= (byte*) "/x00" ,其中*表示零个或多个byte字节,/x00表示结束符;后面的"world"是value值,它的类型一般是string,double,array,binarydata等类型。

使用情况

编辑

MongoDB使用了BSON这种结构来存储数据和网络数据交换。把这种格式转化成一文档这个概念(Document),因为BSON是schema-free的,所以在MongoDB中所对应的文档也有这个特征,这里的一个Document也可以理解成关系数据库中的一条记录(Record),只是这里的Document的变化更丰富一些,如Document可以嵌套。
MongoDB以BSON做为其存储结构的一种重要原因是其可遍历性。

官网

http://bsonspec.org/

BSON [bee · sahn], short for Bin­ary JSON, is a bin­ary-en­coded seri­al­iz­a­tion of JSON-like doc­u­ments. Like JSON, BSON sup­ports the em­bed­ding of doc­u­ments and ar­rays with­in oth­er doc­u­ments and ar­rays. BSON also con­tains ex­ten­sions that al­low rep­res­ent­a­tion of data types that are not part of the JSON spec. For ex­ample, BSON has a Date type and a BinData type.

BSON can be com­pared to bin­ary inter­change for­mats, like Proto­col Buf­fers. BSON is more "schema-less" than Proto­col Buf­fers, which can give it an ad­vant­age in flex­ib­il­ity but also a slight dis­ad­vant­age in space ef­fi­ciency (BSON has over­head for field names with­in the seri­al­ized data).

BSON was de­signed to have the fol­low­ing three char­ac­ter­ist­ics:

  1. Lightweight

    Keep­ing spa­tial over­head to a min­im­um is im­port­ant for any data rep­res­ent­a­tion format, es­pe­cially when used over the net­work.

  2. Traversable

    BSON is de­signed to be tra­versed eas­ily. This is a vi­tal prop­erty in its role as the primary data rep­res­ent­a­tion for Mon­goDB.

  3. Efficient

    En­cod­ing data to BSON and de­cod­ing from BSON can be per­formed very quickly in most lan­guages due to the use of C data types.

JSON比较

https://www.mongodb.com/json-and-bson

Binary JSON (BSON)

MongoDB represents JSON documents in binary-encoded format called BSON behind the scenes. BSON extends the JSON model to provide additional data types, ordered fields, and to be efficient for encoding and decoding within different languages.

MongoDB, BSON, and JSON

The MongoDB BSON implementation is lightweight, fast and highly traversable. Like JSON, MongoDB's BSON implementation supports embedding objects and arrays within other objects and arrays – MongoDB can even 'reach inside' BSON objects to build indexes and match objects against query expressions on both top-level and nested BSON keys. This means that MongoDB gives users the ease of use and flexibility of JSON documents together with the speed and richness of a lightweight binary format.

http://mongodb.github.io/mongo-csharp-driver/2.0/reference/bson/bson/

string outputFileName; // initialize to the file to write to.

using (var stream = File.OpenWrite(outputFileName))
using (var writer = new BsonBinaryWriter(stream))
{
writer.WriteStartDocument();
writer.WriteName("a");
writer.WriteInt32(1);
writer.WriteEndDocument();
}

  

SON

In the same way, we can write a JSON string using a JsonWriter. For example, to write the document { a: 1 }:

string outputFileName; // initialize to the file to write to.

using (var output = new StreamWriter(outputFileName))
using (var writer = new JsonWriter(output))
{
writer.WriteStartDocument();
writer.WriteName("a");
writer.WriteInt32(1);
writer.WriteEndDocument();
}

  

https://blog.csdn.net/zfskkk/article/details/78608844

查询、修改 BSON 大于JSON

总上所述:

数据结构: 
  json是像字符串一样存储的,bson是按结构存储的(像数组 或者说struct)

存储空间 
  bson>json

操作速度 
  bson>json。比如,遍历查找:json需要扫字符串,而bson可以直接定位

修改: 
  json也要大动大移,bson就不需要。

最新文章

  1. ASP.NET MVC的客户端验证:jQuery验证在Model验证中的实现
  2. FineUI(专业版)v3.2.0 发布(ASP.NET UI控件库)!
  3. 收集移动端HTML5/H5使用的插件
  4. geotrellis使用(二十)geotrellis1.0版本新功能及变化介绍
  5. [转]java.lang.OutOfMemoryError:GC overhead limit exceeded
  6. 使用Yeoman快速启动AngularJS项目开发
  7. 关于new/delete、malloc/free的内存泄漏检测
  8. C语言typeof详解 offsetof
  9. SQL Server Profiler监控SQL Server性能
  10. PIGS(最大流)
  11. 偏执的我从Linux到Windows的感受
  12. Unity3D --对撞机/碰撞器 介绍
  13. 201521123019 《Java程序设计》第3周学习总结
  14. 从DataTable中查询数据
  15. Fundebug前端JavaScript插件更新至1.7.1,拆分录屏代码,还原部分Script error.
  16. P1460 健康的荷斯坦奶牛 Healthy(DFS)
  17. mybatis 的sql语句及使用mybatis的动态sql mybatis防注入
  18. SQLServer 学习笔记之超详细基础SQL语句 Part 6
  19. python基础学习14----正则表达式
  20. 【TJOI2015】线性代数

热门文章

  1. 静态链表过程演示及代码实现(A - B) U (B - A)
  2. 基于Spring Boot的可直接运行的分布式ID生成器的实现以及SnowFlake算法详解
  3. Java使用icepdf转高清图片
  4. uwp,c#,全屏播放保持屏幕响应
  5. 1、4 前后端分离,写静态HTML文件,通过ajax 返回数据
  6. socket网络编程 的基本方法:--ongoing
  7. [转帖]Linux 中的零拷贝技术,第 1 部分
  8. java源码 -- AbstractCollection抽象类
  9. java日志框架系列(6):logback框架encoder详解
  10. PAT甲级 并查集 相关题_C++题解