BSON数据格式
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 Binary JSON, is a binary-encoded serialization of JSON-like documents. Like JSON, BSON supports the embedding of documents and arrays within other documents and arrays. BSON also contains extensions that allow representation of data types that are not part of the JSON spec. For example, BSON has a Date type and a BinData type.
BSON can be compared to binary interchange formats, like Protocol Buffers. BSON is more "schema-less" than Protocol Buffers, which can give it an advantage in flexibility but also a slight disadvantage in space efficiency (BSON has overhead for field names within the serialized data).
BSON was designed to have the following three characteristics:
Lightweight
Keeping spatial overhead to a minimum is important for any data representation format, especially when used over the network.
Traversable
BSON is designed to be traversed easily. This is a vital property in its role as the primary data representation for MongoDB.
Efficient
Encoding data to BSON and decoding from BSON can be performed very quickly in most languages 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/
BSON
BsonBinaryWriter
is for writing binary BSON. For example, to write the document{ a: 1 }
to a BSON file: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();
}
JSON
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就不需要。
BSON数据格式的更多相关文章
- 【转】BSON数据格式
原文:https://www.e-learn.cn/content/qita/1999197 ----------------------------------------------------- ...
- 9.6 MongoDB一
目录:ASP.NET MVC企业级实战目录 9.6.1 MongoDB简介 MongoDB是一个高性能,开源,无模式的文档型数据库,是当前NoSql数据库中比较热门的一种.它在许多场景下可用于替代传统 ...
- MongoDB学习笔记(一) MongoDB介绍及安装(摘)
MongoDB是一个高性能,开源,无模式的文档型数据库,是当前NoSql数据库中比较热门的一种.它在许多场景下可用于替代传统的关系型数据库或键/值存储方式.Mongo使用C++开发.Mongo的官方网 ...
- MongoDB【第一篇】MongodDB初识
NoSQL介绍 一.NoSQL简介 NoSQL,全称是”Not Only Sql”,指的是非关系型的数据库. 非关系型数据库主要有这些特点:非关系型的.分布式的.开源的.水平可扩展的. 原始的目的是为 ...
- Mongodb学习笔记一(Mongodb环境配置)
Mongodb学习 说明: MongoDB由databases组成,database由collections组成,collection由documents组成,document由fileds组成.Mo ...
- 2.MongoDB数据库简介
1).简介 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. mongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系 ...
- mongodb 使用场景和不使用场景
1.mongodb介绍 MongoDB (名称来自"humongous") 是一个可扩展的高性能,开源,模式自由,面向文档的数据库.它使用C++编写.MongoDB特点: a.面向 ...
- 基于C#的MongoDB数据库开发应用(1)--MongoDB数据库的基础知识和使用
在花了不少时间研究学习了MongoDB数据库的相关知识,以及利用C#对MongoDB数据库的封装.测试应用后,决定花一些时间来总结一下最近的研究心得,把这个数据库的应用单独作为一个系列来介绍,希望从各 ...
- NOSQL学习笔记系列之MongoDB 一 基础
主题:MongoDB 学习资料参考网址: 1.http://www.w3cschool.cc/mongodb/mongodb-tutorial.html 2.http://www.icoolxue.c ...
随机推荐
- Linux SVN安装
step1:检查是否已经安装Svn Server. svnserve --version step2:执行安装 step3:创建代码仓库 进入对应目录: 说明: conf:配置文件 db:数据存储文件 ...
- windows下编译Grafana前端
本次介绍一下Windows环境源码编译步骤. 准备 安装Go 1.8.1 安装NodeJS LTS 安装Git 安装golang开发环境: 参考链接:https://www.cnblogs.com/ ...
- Delphi 拦截输入法输入结果
{ 拦截输入法输入的字符串.向编辑框中输入中文查看效果. Delphi XE7 } unit Unit1; interface uses Winapi.Windows, Winapi.Messages ...
- apache ranger源码编译
官方文档 http://ranger.apache.org/quick_start_guide.html Quick Start Guide Build Process 1. Check out th ...
- Python 爬虫 之 阅读呼叫转移(一)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/jcjc918/article/details/37533073 你是否苦恼于网上无法下载的& ...
- 数据的偏度和峰度——df.skew()、df.kurt()
我们一般会拿偏度和峰度来看数据的分布形态,而且一般会跟正态分布做比较,我们把正态分布的偏度和峰度都看做零.如果我们在实操中,算到偏度峰度不为0,即表明变量存在左偏右偏,或者是高顶平顶这么一说. 一.偏 ...
- 增强for
什么是增强for? 增强for(也称之为for each)是JDK1.5以后出来的一个高级for循环,专门用来遍历数组和集合的.他的内部原理其实是一个Iterator迭代器,所以在遍历过程中不能对集合 ...
- hibernate 查询字段是重复名字的处理方法
目前遇到了三种情况: 一:当表的字段是数字类型(int,long .....) select name,ifnull(conpih.uh_id,0) from user; 将重复的字段如上修改用ifn ...
- codeforces342B
Xenia and Spies CodeForces - 342B Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined u ...
- Python TypeError: not all arguments converted during string formatting ——元组tuple(a)和(a,)的区别
今天写程序,想输出一个array的shape,原程序为: print('shape of testUImatrix:%s\nStart to make testUImatrix...'%(testui ...