MongoDB版本及存储引擎区别
<h2 class="title sectiontitle" data-spm-anchor-id="a2c4g.11186623.2.i6.6b9a195bpM1oHQ"><img src="https://img2020.cnblogs.com/i-beta/872610/202003/872610-20200313103830062-465367407.png"></h2><h2 id="title-nm6-yur-lh2" class="title sectiontitle" data-spm-anchor-id="a2c4g.11186623.2.i6.6b9a195bpM1oHQ">数据库版本及优势</h2>
<div id="p-w03-tlx-7bw" class="p" data-spm-anchor-id="a2c4g.11186623.2.i7.6b9a195bpM1oHQ">3.4版本在性能和安全性等方面较3.2版本均有不同程度的提升;</div>
<div class="p" data-spm-anchor-id="a2c4g.11186623.2.i7.6b9a195bpM1oHQ">4.0版本更适用于金融等对事务有依赖且使用NoSQL特性的场景;</div>
<div class="p" data-spm-anchor-id="a2c4g.11186623.2.i7.6b9a195bpM1oHQ">4.2版本采用二段提交方式,保证分片集群事务的ACID特性,极大拓展了适用的业务场景。更多详情请参见下表。</div>
<div class="p" data-spm-anchor-id="a2c4g.11186623.2.i7.6b9a195bpM1oHQ"> </div>
<div class="p" data-spm-anchor-id="a2c4g.11186623.2.i7.6b9a195bpM1oHQ">
<table id="table-a81-9qm-l85" class="table">
<thead id="thead-lxw-xuo-j8a" class="thead">
<tr id="row-0da-c69-75d"><th id="concept-qg2-xcr-52b-entry-g3s-ctg-x6n" class="entry" data-spm-anchor-id="a2c4g.11186623.2.i9.6b9a195bpM1oHQ">数据库版本</th><th id="concept-qg2-xcr-52b-entry-mhf-uar-gir" class="entry">优势</th></tr>
</thead>
<tbody id="tbody-s72-bks-81e" class="tbody">
<tr id="row-70m-nbn-c7x">
<td id="entry-2d4-noj-9gq" class="entry">3.4版本</td>
<td id="entry-7dc-b9f-5xf" class="entry">
<ul id="ul-unq-c1e-k3b" class="ul">
<li id="li-78v-r3s-iy8" class="li">更快的主备同步
<p id="p-dm7-4zs-0mj" class="p" data-spm-anchor-id="a2c4g.11186623.2.i8.6b9a195bpM1oHQ">在同步数据的同时建立所有索引(以前的版本仅建立_id索引)。同时在同步数据的阶段,Secondary节点不断读取新的oplog信息,确保Secondary节点的local数据库具备足够的存储空间来存储临时数据。</p>
</li>
<li id="li-8kt-s6i-loi" class="li">更高效的负载均衡
<p id="p-4w8-wcc-gz4" class="p" data-spm-anchor-id="a2c4g.11186623.2.i10.6b9a195bpM1oHQ">3.2及以前版本中,分片集群的负载均衡由Mongos节点负责,多个Mongos节点会抢一个分布式锁,由抢锁成功的Mongos节点执行负载均衡任务,在Shard节点间迁移块;而在3.4版本中,负载均衡由ConfigServer节点中的Primary节点负责,负载均衡的并发度和效率上均有大幅提升。</p>
</li>
<li id="li-ung-3cs-rf5" class="li">更丰富的aggregation操作
<p id="p-gk5-cbh-3l9" class="p">在3.4版本增加了大量的aggregation操作符,可支持更强的数据分析能力。例如,<code id="codeph-ipr-ikk-3b7" class="ph codeph">bucket</code>能便捷地对数据进行分类;<code id="codeph-9o2-0k8-5qv" class="ph codeph">$grahpLookup</code>相较于3.2版本的<code id="codeph-t48-bc4-t76" class="ph codeph">$lookup</code>能支持更复杂的关系运算;<code id="codeph-vg2-4h4-2p1" class="ph codeph">$addFields</code>使得文档操作更丰富(例如将某些字段求和存储为新的字段)。</p>
</li>
<li id="li-ze7-9v8-hh0" class="li">支持Sharding Zones
<p id="p-edi-ou1-jm0" class="p">分片集群里引入了Zone的概念,主要取代现在的tag-aware sharding机制,能将某些数据分配到指定的一个或多个Shard节点中,该特性极大地方便sharding cluster的跨机房部署。</p>
</li>
<li id="li-ta5-3l8-d9l" class="li">支持Collation
<p id="p-tmf-b7f-t0e" class="p">在之前的版本里,文档里存储的字符串不论是中英文还是大小写,一律按字节来对比;引入Collation后,支持对字符串的内容进行解读,可以按使用的locale进行对比,也支持在对比时忽略大小写。</p>
</li>
<li id="li-rkt-b49-2o3" class="li">支持只读视图(Read-only views)
<p id="p-axm-coh-ph2" class="p">在3.4中增加了对只读视图的支持,可以将集合中满足某个查询条件的数据虚拟成一个特殊的集合,用户可以在特殊的集合上做进一步的查询操作。</p>
</li>
</ul>
</td>
</tr>
<tr id="row-64p-ihw-dl3">
<td id="entry-ezj-f23-b5q" class="entry">4.0版本</td>
<td id="entry-xa0-svo-sk6" class="entry">
<ul id="ul-i0t-9p7-md0" class="ul">
<li id="li-aoi-ruw-lco" class="li">跨文档事务支持
<p id="p-tq4-ry7-4zg" class="p">首个支持跨文档事务的NoSQL云数据库,将文档模型的速度,灵活性、功能与ACID保证相结合。</p>
</li>
<li id="li-q5m-vhl-rwq" class="li">迁移速度提升40%
<p id="p-glg-lp3-7y1" class="p">并发的读取和写入,使得新增的Shard节点能更快地完成数据迁移以承载业务压力。</p>
</li>
<li id="li-8y0-vf5-eo1" class="li">读性能大幅扩展
<p id="p-ha6-bwd-5jd" class="p">借助事务特性,Secondary节点不再因为同步日志而阻塞读取请求。 阿里云同时在全体系版本支持多节点扩展功能,可大幅提升业务读取能力。</p>
</li>
</ul>
</td>
</tr>
<tr id="row-ia0-1oi-s2k">
<td id="entry-hnn-6ef-lxw" class="entry">4.2版本</td>
<td id="entry-kl7-x3h-l2n" class="entry">
<ul id="ul-mwt-hba-rc5" class="ul">
<li id="li-53s-d82-fy5" class="li">分布式事务
<p id="p-rlr-msz-ddl" class="p">采用二段提交方式,保证分片集群事务的ACID特性,极大拓展了MongoDB的业务场景,实现从NoSQL到NewSQL的飞跃。</p>
</li>
<li id="li-e2d-5s8-h17" class="li">可重试读
<p id="p-eik-5l8-sf3" class="p">增加可重试读功能,提供弱网环境下自动重试能力,降低业务端的逻辑复杂性,保证用户业务的连续性。</p>
</li>
<li id="li-t3b-vfz-728" class="li">通配符索引
<p id="p-t82-d6x-pj3" class="p">对于非确定字段,支持创建通配符索引覆盖一个文档下的多个特征字段,管理方便且使用灵活。</p>
</li>
<li id="li-ml5-pli-b2v" class="li">字段级加密
<p id="p-vtv-8eo-18b" class="p" data-spm-anchor-id="a2c4g.11186623.2.i13.6b9a195bpM1oHQ">驱动层面支持字段级加密,可以针对特定的敏感信息(例如账号、密码、价格、手机号等)单独加密。避免全库加密,提升业务灵活性和安全性。</p>
</li>
<li id="li-9he-sg0-ie1" class="li">物化视图
<p id="p-grm-7cv-ubb" class="p" data-spm-anchor-id="a2c4g.11186623.2.i12.6b9a195bpM1oHQ">通过最新的物化视图可以缓存计算结果,避免重复计算提升运行效率,减少逻辑复杂度。</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<h2 id="title-7x5-dgv-esz" class="title sectiontitle">存储引擎</h2>
<table id="table-nn8-gfg-osf" class="table"><caption> </caption><colgroup><col><col><col></colgroup>
<thead id="thead-37o-olf-dhi" class="thead">
<tr id="row-nqw-8ij-dxk"><th id="concept-qg2-xcr-52b-entry-pck-88a-9zf" class="entry">存储引擎</th><th id="concept-qg2-xcr-52b-entry-mtr-rdt-527" class="entry">说明</th><th id="concept-qg2-xcr-52b-entry-dgy-ofu-p9f" class="entry">适用场景</th></tr>
</thead>
<tbody id="tbody-fl9-klb-0ag" class="tbody">
<tr id="row-th0-wl2-m81">
<td id="entry-9zg-wcb-9qw" class="entry">WiredTiger</td>
<td id="entry-mkh-ili-dpg" class="entry">基于BTree结构组织数据,相比MongoDB早期的MMAPv1存储引擎性能提升明显,且支持数据压缩,存储成本更低。</td>
<td id="entry-yz8-f7q-2h0" class="entry">默认存储引擎,适用于大多数业务场景。</td>
</tr>
<tr id="row-vhv-py7-qbq">
<td id="entry-65y-p1i-xeg" class="entry">RocksDB(已下线)</td>
<td id="entry-aba-hcj-f5w" class="entry">基于LSM tree结构组织数据,针对性优化数据写入,将随机写入转换成了顺序写入,能保证持续高效的数据写入。</td>
<td id="entry-9xd-s2d-6p9" class="entry">适用于大量写且少读的场景。</td>
</tr>
<tr id="row-n90-huj-gwo">
<td id="entry-poj-op0-hog" class="entry">TerarkDB(已下线)</td>
<td id="entry-y3k-u4r-5v3" class="entry">借助TerarkDB的全局压缩技术,在提高压缩率的同时,能大幅提高随机查询的性能。</td>
<td id="entry-qui-218-axa" class="entry" data-spm-anchor-id="a2c4g.11186623.2.i14.6b9a195bpM1oHQ">适用于多读少写或批量写大量读的场景。</td>
</tr>
</tbody>
</table>
<h2 id="title-v2o-ubp-s73" class="title sectiontitle" data-spm-anchor-id="a2c4g.11186623.2.i15.6b9a195bpM1oHQ">版本和存储引擎的适配关系</h2>
<p id="p-vl7-h9a-m5c" class="p"><span id="ph-w06-4u4-4dh" class="ph">为最大化满足各类业务场景需求,云数据库MongDB提供了WiredTiger、RocksDB和TerarakDB三种存储引擎供您选择。存储引擎与版本间的适配关系如下:</span></p>
<table id="table-rcg-dne-1d8" class="table"><caption> </caption><colgroup><col><col><col><col></colgroup>
<thead id="thead-l8t-7gm-6ug" class="thead">
<tr id="row-y2g-mxe-5ci"><th id="concept-qg2-xcr-52b-entry-wpc-k5l-tfi" class="entry align-left">存储引擎</th><th id="concept-qg2-xcr-52b-entry-rpg-esa-4a8" class="entry align-left">3.4版本</th><th id="concept-qg2-xcr-52b-entry-wwy-2e5-gub" class="entry align-left">4.0版本</th><th id="concept-qg2-xcr-52b-entry-4k6-575-n4d" class="entry">4.2版本</th></tr>
</thead>
<tbody id="tbody-9w5-1ln-9ge" class="tbody">
<tr id="row-mkb-sl0-4gn">
<td id="entry-ned-ae7-6du" class="entry align-left">WiredTiger</td>
<td id="entry-b8b-brw-2h6" class="entry align-left">
<p id="p-24a-3u2-owc" class="p">单节点实例</p>
<p id="p-zxd-rf8-oqm" class="p">副本集实例</p>
<p id="p-byl-gjr-q0y" class="p">分片集群实例</p>
</td>
<td id="entry-g64-bt3-ooh" class="entry align-left">
<p id="p-5vc-nf0-nzk" class="p">单节点实例</p>
<p id="p-10u-ywr-o42" class="p">副本集实例</p>
<p id="p-mdu-ab6-953" class="p">分片集群实例</p>
</td>
<td id="entry-21h-i6n-adl" class="entry">
<p id="p-wa6-sal-uu5" class="p" data-spm-anchor-id="a2c4g.11186623.2.i16.6b9a195bpM1oHQ">副本集实例</p>
<p id="p-o55-y8w-a59" class="p" data-spm-anchor-id="a2c4g.11186623.2.i17.6b9a195bpM1oHQ">分片集群实例</p>
</td>
</tr>
<tr id="row-tf7-r8z-6sw">
<td id="entry-lrb-htg-lr5" class="entry align-left">RocksDB(已下线)</td>
<td id="entry-xjj-gpw-28x" class="entry align-left">
<p id="p-ve5-9mq-pi7" class="p">单节点实例(按量付费)</p>
<p id="p-mkh-u2g-p3g" class="p">副本集实例(按量付费)</p>
<p id="p-a7c-tgx-4rc" class="p">分片集群实例</p>
</td>
<td id="entry-cf7-zaj-rub" class="entry align-left">-</td>
<td id="entry-5yi-3o4-fis" class="entry">-</td>
</tr>
<tr id="row-6s6-qep-c9t">
<td id="entry-fvw-ti9-4pp" class="entry align-left">TerarkDB(已下线)</td>
<td id="entry-q98-xsr-81t" class="entry align-left">
<p id="p-5f2-h41-cie" class="p">分片集群实例</p>
</td>
<td id="entry-x6f-o9q-dn2" class="entry align-left">-</td>
<td id="entry-54a-un6-ojw" class="entry">
<p>-</p>
<p> </p>
</td>
</tr>
</tbody>
</table>
<h2><span>MongoDB的版本</span></h2>
<p class="first admonition-title"><span>重要:</span></p>
<p class="last"><span>始终升级到发行系列的最新稳定版本。</span></p>
<p><span>MongoDB的版本的形式</span><code class="docutils literal">X.Y.Z</code><span>在那里</span><code class="docutils literal">X.Y</code><span> 指的是一个版本系列或开发系列</span><code class="docutils literal">Z</code><span> 指修订/补丁号。</span></p>
<ul class="simple">
<li><span>如果</span><code class="docutils literal">Y</code><span>是偶数,则</span><code class="docutils literal">X.Y</code><span><span>指发布系列;</span><span>例如, </span></span><code class="docutils literal">4.0</code><span>发行系列和</span><code class="docutils literal">4.2</code><span><span>发行系列。</span><span>发布系列 </span></span>稳定<span>且适合生产。</span></li>
<li><span>如果</span><code class="docutils literal">Y</code><span>是奇数,则</span><code class="docutils literal">X.Y</code><span><span>指一个开发系列;</span><span>例如, </span></span><code class="docutils literal">4.1</code><span>开发系列和</span><code class="docutils literal">4.3</code><span><span>开发系列。</span><span>开发系列仅</span></span>用于测试而不是生产<span>。</span></li>
</ul>
<p><span>例如,在MongoDB版本中</span><code class="docutils literal">4.0.12</code><span>,</span><code class="docutils literal">4.0</code><span>是指发行系列和</span><code class="docutils literal">.12</code><span>版本。</span></p>
<div id="new-releases" class="section">
<h2><span>最新产品</span></h2>
<p><span>在发布一系列变化(例如</span><code class="docutils literal">4.0</code><span>到</span><code class="docutils literal">4.2</code><span>)通常标志着引进可能破坏向后兼容的新功能。</span></p>
</div>
<div id="patch-releases" class="section">
<h2><span>补丁版本</span></h2>
<p><span>更改版本号(如</span><code class="docutils literal">4.0.11</code><span>对</span><code class="docutils literal">4.0.12</code><span>)一般标注错误修复和向后兼容的改变的释放。</span></p>
</div>
<div id="driver-versions" class="section">
<h2><span>驱动程序版本</span></h2>
<p><span>MongoDB的版本编号系统与MongoDB驱动程序使用的系统不同。</span></p>
</div>
<p><strong>官方发行说明</strong>:<span style="color: rgba(0, 0, 255, 1)"><span style="color: rgba(0, 0, 255, 1)">https://docs.mongodb.com/manual/release-notes/</span></span></p>
</div>
</div>
<div id="MySignature" role="contentinfo">
<div id="AllanboltSignature">
<div>作者:Tse先生</div>
<div>出处:https://www.cnblogs.com/Sungeek/</div>
<div>邮箱:vim10086@qq.com</div>
<div>本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。</div>
</div><br><br>
来源:https://www.cnblogs.com/Sungeek/p/12485009.html
頁:
[1]