DEV Community

Cover image for 🌐 入门: MongoDB 更改流、并发、备份快照和检查点、复合通配符索引
Danny Chan for MongoDB Builders

Posted on

2 2 2 2 2

🌐 入门: MongoDB 更改流、并发、备份快照和检查点、复合通配符索引

💫 更改流:

  • 用例: 大型文档、预映像、后映像
  • 访问实时数据更改
  • 订阅数据库上的所有数据更改,然后对其做出反应
  • 适用于副本集和分片集群
  • 必须使用 WiredTiger 存储引擎
  • 可以使用加密at-rest


🕰️ 时间序列数据:

  • 高容量数据集
  • 改进的存储优化和压缩
  • 高基数数据
  • 细粒度更新和删除
{
    "metadata": { "sensorId": 5578, "type": "temperature" },
    "timestamp": ISODate("2021-05-18T00:00:00.000Z"),
    "temp": 12
}
Enter fullscreen mode Exit fullscreen mode



并发:



🔒 WiredTiger 存储引擎:

  • 无法将文档固定到 WiredTiger 缓存
  • 无法为读取和写入保留缓存的一部分
  • 大量写入工作负载会影响性能
  • 将其缓存分配给整个 MongoDB 实例


🌍 功能: 事务(读写)并发:

  • 动态调整最大并发存储引擎事务(读取和写入)数量
  • 在集群过载期间优化数据库吞吐量
  • 永不超过 128 个读写票
  • 读写始终相等


🔍文档级并发控制:

  • WiredTiger 控制写操作
  • 多个客户端可以同时修改集合的不同文档
  • 全局、数据库和集合级的意图锁
  • 检测两个操作之间的冲突,一个将由于冲突操作而停止,另一个继续进行
  • 透明地重试冲突操作



备份:



🛡️功能: 时间点快照
多版本并发控制 (MVCC)


🗄️ 功能: 检查点

  • 充当恢复点
  • 数据文件中现在持久化的数据
  • 一致到最后一个检查点
  • 每 60 秒将快照数据写入磁盘
  • 如果 MongoDB 在写入新检查点时遇到错误, MongoDB 可以从最后一个有效检查点恢复


📜 日志:

  • 通过带有检查点的预写日志 (journal) 确保数据持久性
  • 在检查点之间保持所有数据修改
  • MongoDB 在检查点之间出错,使用日志重放所有修改的数据


📜 压缩:

  • 为集合提供 Snappy 压缩
  • 为索引提供前缀压缩 (消除公共前缀)


📜 内存使用:

  • 利用 WiredTiger 内部缓存和文件系统缓存


📜 块压缩:

  • 提供显著的磁盘存储节省
  • WiredTiger 内部缓存中的集合数据是未压缩的,可以进行操作



复合通配符索引:



🔍 功能: 复合通配符索引

  • 一个通配符索引替换大量单独的索引
  • 可以有效地覆盖许多潜在的查询 应用于属性模式


{ tenantId: 1, "customFields.addr": 1 }
{ tenantId: 1, "customFields.name": 1 }
{ tenantId: 1, "customFields.blockId": 1 }
Enter fullscreen mode Exit fullscreen mode


{ tenantId: 1, "customFields.$**": 1 }
Enter fullscreen mode Exit fullscreen mode



更多功能:



🔄 集群到集群同步(mongosync)

  • 同步特定数据集而不是整个集群


📊 近似百分位数

  • 在 $group 阶段使用 $percentile 作为累加器,或作为聚合表达式 记录:
{ studentId: "2345", test01: 62, test02: 81, test03: 80 }
Enter fullscreen mode Exit fullscreen mode

结果:

{ studentId: '2345', testPercentiles: [ 80, 81 ] }
Enter fullscreen mode Exit fullscreen mode


👤 用户角色

  • 在聚合管道中使用用户角色变量
  • 示例: 应用程序根据用户权限显示不同的数据


🔒 可查询加密

  • 安全性
  • 完全随机的加密数据

Editor

Image description

Danny Chan, specialty of FSI and Serverless

Image description

Kenny Chan, specialty of FSI and Machine Learning

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay