MongoDB-CN-Manual
  • MongoDB中文手册|官方文档中文版
  • MongoDB用户手册说明
  • MongoDB简介
    • 入门
    • 数据库和集合
      • 视图
      • 按需物化视图
      • 封顶集合
      • 时间序列集合
    • 文档
    • BSON类型
      • Comparison and Sort Order
      • MongoDB Extended JSON (v2)
      • MongoDB Extended JSON (v1)
  • 安装 MongoDB
    • 安装MongoDB社区版
      • 在Linux上安装MongoDB社区版
      • 在macOS上安装MongoDB社区版
      • 在Windows上安装MongoDB社区版
    • 安装MongoDB企业版
      • 在Linux上安装MongoDB企业版
      • 在Mac OS安装MongoDB企业版
      • 在Windows安装MongoDB企业版
      • 使用Docker安装MongoDB企业版
    • 将社区版MongoDB升级到企业版MongoDB
    • 验证MongoDB软件包的完整性
  • The mongo Shell
    • 配置mongo Shell
    • 使用 mongo Shell帮助
    • 为mongo Shell编写脚本
    • mongo Shell中的数据类型
    • mongo Shell 快速参考
  • MongoDB CRUD操作
    • 插入文档
      • 插入方法
    • 查询文档
      • 在mongo Shell中迭代游标
      • 从查询返回的项目字段
      • 查询嵌入式文档数组
      • 查询数组
      • 查询空字段或缺少字段
      • 查询嵌入/嵌套文档
    • 更新文档
      • 更新方法
      • 聚合管道更新
    • 删除文档
      • 删除方法
    • 地理空间查询
      • 用地理空间查询查找餐馆
      • GeoJSON对象
    • 批量写入操作
    • 可重试写入
    • 可重试读取
    • SQL到MongoDB的映射图表
    • 文本搜索
      • 文本索引
      • 文本索引操作
      • 集合管道中的文本索引
      • 文本索引语言
    • Read Concern读关注
      • 读关注 "local"
      • 读关注 "available"
      • 读关注 "majority"
      • 读关注 "linearizable"
      • 读关注 "snapshot"
    • Write Concern写关注
    • MongoDB CRUD概念
      • 原子性和事务
      • 读隔离性,一致性和近因性
        • 因果一致性和读写关注
      • 分布式查询
      • 通过findAndModify进行线性化读取
      • 查询计划
      • 查询优化
        • 评估当前操作性能
        • 优化查询性能
        • 写操作性能
        • 说明结果
      • 分析查询表现
      • Tailable 游标
  • MongoDB聚合
    • 聚合管道
      • 聚合管道优化
      • 聚合管道限制
      • 聚合管道和分片集合
      • 使用 Zip Code 数据集进行聚合
      • 使用用户首选项数据进行聚合
    • Map-Reduce
      • Map-Reduce 和分片集合
      • Map-Reduce 并发
      • Map-Reduce 示例
      • 执行增量 Map-Reduce
      • 对 Map Function 进行故障排除
      • 排除 Reduce Function 问题
      • Map-Reduce转换到聚合管道
    • 聚合参考
      • 聚合管道快速参考
      • 聚合命令
      • 聚合命令对比
      • 聚合表达式中的变量
      • SQL 到聚合映射图表
  • MongoDB数据模型
    • 数据建模介绍
    • 模式验证
    • 数据模型设计
      • 一对一嵌套关系模型
  • MongoDB事务
  • MongoDB事务
    • 驱动程序 API
    • 生产注意事项
    • 生产注意事项 (分片集群)
    • 事务操作
  • MongoDB索引
    • 单字段索引
    • 复合索引
    • 多键索引
      • 多键索引范围
    • 文本索引
      • 为文本索引指定语言
      • 指定文本索引的名称
      • 用权重控制搜索结果
      • 限制扫描条目的数量
    • 通配符索引
      • 通配符索引限制
    • 2dsphere 索引
      • 查询一个2dsphere索引
    • 2d 索引
      • 创建一个2d索引
      • 查询一个2d索引
      • 2d索引内部
      • 使用球面几何计算距离
    • geoHaystack 索引
      • 创建Haystack索引
      • 查询Haystack索引
    • 哈希索引
    • 索引特性
      • TTL 索引
        • 通过设置TTL使集合中的数据过期
      • 唯一索引
      • 部分索引
      • 不分大小写索引
      • Sparse 索引
    • 在填充的集合上建立索引
      • 在副本集上建立滚动索引
      • 在分片群集上建立滚动索引
    • 索引交集
    • 管理索引
    • 衡量索引使用
    • 索引策略
      • 创建索引来支持查询
      • 使用索引对查询结果进行排序
      • 确保索引适合RAM
      • 创建以确保选择性的查询
    • 索引参考
  • MongoDB安全
    • 安全检查列表
    • 启用访问控制
    • 身份验证
      • 用户
        • 添加用户
        • 权限认证机制
          • SCRAM
            • 用x.509证书来认证客户端
    • 审计
      • 配置审计过滤器
      • 配置审计
      • 系统事件审计消息
    • 网络和配置强化
    • 安全参考
      • system.roles集合
      • system.users集合
      • 资源文档
      • 权限操作
    • 附录
      • 附录-A-用于测试的 OpenSSl CA 证书
      • 附录-B-用于测试的OpenSSL服务器证书
      • 附录-C-用于测试的OpenSSL客户端证书
  • Change Streams变更流
    • 变更流生产建议
    • 变更事件
  • MongoDB复制
    • 副本集成员
    • 副本集日志
    • 副本集数据同步
    • 副本集部署架构
    • 副本集成员配置教程
    • 副本集维护教程
    • MongoDB复制参考
  • MongoDB分片
    • 分片集群组件
    • 分片键
    • 哈希分片
    • 范围分片
    • 区
      • 管理分片区
      • 按位置细分数据
      • 用于更改SLA或SLO的分层硬件
      • 按应用或客户细分数据
      • 仅插入工作负载的分布式本地写入
      • 管理分片区
    • 使用块进行数据分区
      • 在分片集群中拆分数据块
    • 分片管理
      • 查看集群设置
    • 重启一个分片集群
    • [把一个分片集群迁移到不同的硬件](fen-pian/migrate-a -sharded-cluster-to-different-hardware.md)
    • 分片参考
  • MongoDB管理
    • 产品说明
    • 操作检查列表
    • 开发检查列表
    • 配置和维护
    • 性能
    • 数据中心意识
      • MongoDB部署中的工作负载隔离
      • 区
        • 管理分片区
        • 按位置细分数据
        • 用于更改SLA或SLO的分层硬件
        • 按应用或客户细分数据
        • 仅插入工作负载的分布式本地写入
        • 管理分片区
    • MongoDB备份方法
    • MongoDB监控
  • MongoDB存储
    • 存储引擎
      • WiredTiger 存储引擎
      • 内存存储引擎
    • 日志记录
      • 管理日志记录
        • GridFS
        • FAQ:MongoDB 存储
  • MongoDB参考
    • 运算符
      • 查询与映射运算符
        • 比较查询运算符
          • $eq
          • $gt
          • $gte
          • $in
          • $lt
          • $lte
          • $ne
          • $nin
        • 逻辑查询运算符
          • $and
          • $not
          • $nor
          • $or
        • 元素查询运算符
        • 评估查询运算符
        • 地理空间查询运算符
        • 数组查询运算符
        • 按位查询运算符
        • $comment
        • 映射运算符
      • 更新运算符
        • 字段更新运算符
        • 数组更新运算符
        • 按位更新运算符
      • 聚合管道阶段
      • 聚合管道操作符
        • $abs (aggregation)
        • $acos (aggregation)
        • $acosh (aggregation)
        • $add (aggregation)
        • $addToSet (aggregation)
        • $allElementsTrue (aggregation)
        • $and (aggregation)
        • $anyElementTrue (aggregation)
        • $arrayElemAt (aggregation)
        • $arrayToObject (aggregation)
        • $asin (aggregation)
        • $asinh (aggregation)
        • $atan (aggregation)
        • $atan2 (aggregation)
        • $atanh (aggregation)
        • $avg (aggregation)
        • $ceil (aggregation)
        • $cmp (aggregation)
        • $concat (aggregation)
        • $concatArrays (aggregation)
        • $cond (aggregation)
        • $convert (aggregation)
        • $cos (aggregation)
        • $dateFromParts (aggregation)
        • $dateToParts (aggregation)
        • $dateFromString (aggregation)
        • $literal (aggregation)
      • 查询修饰符
    • 数据库命令
      • 聚合命令
      • 地理空间命令
      • 查询和写操作命令
      • 查询计划缓存命令
      • 认证命令
      • 用户管理命令
      • 角色管理命令
      • 复制命令
      • 分片命令
      • 会话命令
      • 管理命令
      • 诊断命令
      • 免费监控命令
      • 系统事件审计命令
    • mongo Shell 方法
      • 集合方法
        • db.collection.aggregate()
        • db.collection.bulkWrite()
        • db.collection.copyTo()
        • db.collection.count()
        • db.collection.countDocuments()
        • db.collection.estimatedDocumentCount()
        • db.collection.createIndex()
        • db.collection.createIndexes()
        • db.collection.dataSize()
        • db.collection.deleteOne()
        • db.collection.deleteMany()
        • db.collection.distinct()
        • db.collection.drop()
        • db.collection.dropIndex()
        • db.collection.dropIndexes()
        • db.collection.ensureIndex()
        • db.collection.explain()
        • db.collection.find()
        • db.collection.findAndModify()
        • db.collection.findOne()
        • db.collection.findOneAndDelete()
        • db.collection.findOneAndReplace()
        • db.collection.findOneAndUpdate()
        • db.collection.getIndexes()
        • db.collection.getShardDistribution()
        • db.collection.getShardVersion()
        • db.collection.insert()
        • db.collection.insertOne()
        • db.collection.insertMany()
        • db.collection.isCapped()
        • db.collection.latencyStats()
        • db.collection.mapReduce()
        • db.collection.reIndex()
        • db.collection.remove()
        • db.collection.renameCollection()
        • db.collection.replaceOne()
        • db.collection.save()
        • db.collection.stats()
        • db.collection.storageSize()
        • db.collection.totalIndexSize()
        • db.collection.totalSize()
        • db.collection.update()
        • db.collection.updateOne()
        • db.collection.updateMany()
        • db.collection.watch()
        • db.collection.validate()
    • MongoDB中的限制与阈值
    • MongoDB系统集合
    • 词汇表
    • 默认的MongoDB端口
    • 默认的MongoDB读/写关注
    • 服务器会话
  • MongoDB FAQ
    • FAQ: MongoDB基础知识
    • FAQ: MongoDB索引
    • FAQ: MongoDB并发
    • FAQ: MongoDB分片
    • FAQ: MongoDB复制和副本集
    • FAQ: MongoDB存储
    • FAQ: MongoDB诊断
  • MongoDB 版本管理
  • 联系我们
    • Tapdata Cloud
    • MongoDB中文社区
    • 社区合作伙伴—锦木信息
由 GitBook 提供支持
在本页

最后更新于3年前

在本页面

定义

  • db.collection. stats(选项)

返回有关集合的统计信息。

该方法包括以下参数:

参数
类型
描述

仅指定scale因素,MongoDB支持旧格式:

该db.collection.stats()方法提供了围绕数据库命令的包装collStats。

行为

缩放大小

除非度量标准名称(例如"bytes currently in the cache" )另外指定,与大小相关的值以字节为单位显示,可以按比例覆盖。

比例因子将受影响的大小值四舍五入为整数。

存储引擎

根据存储引擎,返回的数据可能不同。有关字段的详细信息,请参阅输出详细信息。

意外关机后的准确性

使用Wired Tiger存储引擎不正常关闭mongod后,db.collection.stats()报告的计数和大小统计信息可能不准确。

偏移量取决于在最后检查站和不干净关闭之间执行的 insert,update 或 delete 操作的数量。检查点通常每 60 秒发生一次。但是,使用 non-default --syncdelay设置运行mongod实例可能会有更多或更少的检查点。

在mongod上的每个集合上运行验证以在不正常关闭后恢复正确的统计信息。

索引过滤器行为

使用indexDetailsKey或indexDetailsName过滤indexDetails将仅_return 单个匹配的索引。如果未找到确切的 match,indexDetails将显示有关集合的所有索引的信息。

indexDetailsKey字段采用以下形式的文档:

其中<string>是索引的字段,<value>是索引的方向,或特殊索引类型,如text或2dsphere。有关索引类型的完整列表,请参见索引类型。

意外停机和计数

对于使用WiredTiger存储引擎的 MongoDB 实例,在不正常关闭后,大小和计数的统计信息可能会被collStats,dbStats,计数报告最多 1000 个文档。要恢复集合的正确统计信息,请在集合上运行 run 验证。

进行中索引

从MongoDB 4.2开始,db.collection.stats包括有关当前正在构建的索引的信息。有关详细信息,请参见:

  • collStats.nindexes

  • collStats.indexDetails

  • collStats.indexBuilds

  • collStats.totalIndexSize

  • collStats.indexSizes

例子

注意

您可以在入门指南中找到用于这些示例的集合数据

基本统计查询

以下操作返回restaurants集合上的统计信息:

操作返回:

由于统计数据未给出比例参数,因此所有大小值都在bytes中。

带有比例的统计查询

以下操作通过指定scale的scale来更改从bytes到kilobytes的数据比例:

操作返回:

带索引详细信息的统计查找

以下操作将创建一个indexDetails文档,其中包含与集合中每个索引相关的信息:

操作返回:

带有过滤索引详细信息的统计信息查找

要过滤indexDetails字段中的索引,可以使用indexDetailsKey选项指定索引键,也可以使用indexDetailsName指定索引 name。要发现集合的索引键和名称,请使用db.collection.getIndexes()。

给定以下索引:

以下操作将indexDetails文档过滤为indexDetailsKey文档定义的单个索引。

以下操作将indexDetails文档过滤为indexDetailsName文档定义的单个索引。

两个操作都会 return 相同的输出:

有关输出的说明,请参阅输出细节。

也可以看看

$collStats

译者:李冠飞

校对:

{ '<string>' : <value>, '<string>' : <value>, ... }
db.restaurants.stats()
{
    "ns" : "guidebook.restaurants",
    "count" : 25359,
    "size" : 10630398,
    "avgObjSize" : 419,
    "storageSize" : 4104192
    "capped" : false,
    "wiredTiger" : {
        "metadata" : {
            "formatVersion" : 1
        },
        "creationString" : "allocation_size=4KB,app_metadata=(formatVersion=1),block_allocation=best,block_compressor=snappy,cache_resident=0,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=0,extractor=,format=btree,huffman_key=,huffman_value=,immutable=0,internal_item_max=0,internal_key_max=0,internal_key_truncate=,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=),lsm=(auto_throttle=,bloom=,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=0,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=0,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
        "type" : "file",
        "uri" : "statistics:table:collection-2-7253336746667145592",
        "LSM" : {
            "bloom filters in the LSM tree" : 0,
            "bloom filter false positives" : 0,
            "bloom filter hits" : 0,
            "bloom filter misses" : 0,
            "bloom filter pages evicted from cache" : 0,
            "bloom filter pages read into cache" : 0,
            "total size of bloom filters" : 0,
            "sleep for LSM checkpoint throttle" : 0,
            "chunks in the LSM tree" : 0,
            "highest merge generation in the LSM tree" : 0,
            "queries that could have benefited from a Bloom filter that did not exist" : 0,
            "sleep for LSM merge throttle" : 0
        },
        "block-manager" : {
            "file allocation unit size" : 4096,
            "blocks allocated" : 338,
            "checkpoint size" : 4096000,
            "allocations requiring file extension" : 338,
            "blocks freed" : 0,
            "file magic number" : 120897,
            "file major version number" : 1,
            "minor version number" : 0,
            "file bytes available for reuse" : 0,
            "file size in bytes" : 4104192
        },
        "btree" : {
            "btree checkpoint generation" : 15,
            "column-store variable-size deleted values" : 0,
            "column-store fixed-size leaf pages" : 0,
            "column-store internal pages" : 0,
            "column-store variable-size leaf pages" : 0,
            "pages rewritten by compaction" : 0,
            "number of key/value pairs" : 0,
            "fixed-record size" : 0,
            "maximum tree depth" : 3,
            "maximum internal page key size" : 368,
            "maximum internal page size" : 4096,
            "maximum leaf page key size" : 3276,
            "maximum leaf page size" : 32768,
            "maximum leaf page value size" : 67108864,
            "overflow pages" : 0,
            "row-store internal pages" : 0,
            "row-store leaf pages" : 0
        },
        "cache" : {
            "bytes read into cache" : 9309503,
            "bytes written from cache" : 10817368,
            "checkpoint blocked page eviction" : 0,
            "unmodified pages evicted" : 0,
            "page split during eviction deepened the tree" : 0,
            "modified pages evicted" : 1,
            "data source pages selected for eviction unable to be evicted" : 0,
            "hazard pointer blocked page eviction" : 0,
            "internal pages evicted" : 0,
            "pages split during eviction" : 1,
            "in-memory page splits" : 1,
            "overflow values cached in memory" : 0,
            "pages read into cache" : 287,
            "overflow pages read into cache" : 0,
            "pages written from cache" : 337
        },
        "compression" : {
            "raw compression call failed, no additional data available" : 0,
            "raw compression call failed, additional data available" : 0,
            "raw compression call succeeded" : 0,
            "compressed pages read" : 287,
            "compressed pages written" : 333,
            "page written failed to compress" : 0,
            "page written was too small to compress" : 4
        },
        "cursor" : {
            "create calls" : 1,
            "insert calls" : 25359,
            "bulk-loaded cursor-insert calls" : 0,
            "cursor-insert key and value bytes inserted" : 10697901,
            "next calls" : 76085,
            "prev calls" : 1,
            "remove calls" : 0,
            "cursor-remove key bytes removed" : 0,
            "reset calls" : 25959,
            "restarted searches" : 0,
            "search calls" : 0,
            "search near calls" : 594,
            "update calls" : 0,
            "cursor-update value bytes updated" : 0
        },
        "reconciliation" : {
            "dictionary matches" : 0,
            "internal page multi-block writes" : 1,
            "leaf page multi-block writes" : 2,
            "maximum blocks required for a page" : 47,
            "internal-page overflow keys" : 0,
            "leaf-page overflow keys" : 0,
            "overflow values written" : 0,
            "pages deleted" : 0,
            "page checksum matches" : 0,
            "page reconciliation calls" : 4,
            "page reconciliation calls for eviction" : 1,
            "leaf page key bytes discarded using prefix compression" : 0,
            "internal page key bytes discarded using suffix compression" : 333
        },
        "session" : {
            "object compaction" : 0,
            "open cursor count" : 1
        },
        "transaction" : {
            "update conflicts" : 0
        }
    },
    "nindexes" : 4,
    "totalIndexSize" : 626688,
    "indexSizes" : {
        "_id_" : 217088,
        "borough_1_cuisine_1" : 139264,
        "cuisine_1" : 131072,
        "borough_1_address.zipcode_1" : 139264
    },
    "ok" : 1
}
db.restaurants.stats( { scale : 1024 } )
{
    "ns" : "guidebook.restaurants",
    "count" : 25359,
    "size" : 10381,
    "avgObjSize" : 419,
    "storageSize" : 4008,
    "capped" : false,
    "wiredTiger" : {
        ...
    },
    "nindexes" : 4,
    "totalIndexSize" : 612,
    "indexSizes" : {
        "_id_" : 212,
        "borough_1_cuisine_1" : 136,
        "cuisine_1" : 128,
        "borough_1_address.zipcode_1" : 136
    },
    "ok" : 1
}
db.restaurant.stats( { indexDetails : true } )
{
    "ns" : "guidebook.restaurants",
    "count" : 25359,
    "size" : 10630398,
    "avgObjSize" : 419,
    "storageSize" : 4104192,
    "capped" : false,
    "wiredTiger" : {
        ...
    },
    "nindexes" : 4,
    "indexDetails" : {
        "_id_" : {
            "metadata" : {
                "formatVersion" : 6,
                "infoObj" : "{ "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "blogs.posts" }"
             },
            "creationString" : "allocation_size=4KB,app_metadata=(formatVersion=6,infoObj={ "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "blogs.posts" }),block_allocation=best,block_compressor=,cache_resident=0,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=0,extractor=,format=btree,huffman_key=,huffman_value=,immutable=0,internal_item_max=0,internal_key_max=0,internal_key_truncate=,internal_page_max=16k,key_format=u,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=16k,leaf_value_max=0,log=(enabled=),lsm=(auto_throttle=,bloom=,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=0,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=true,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=75,type=file,value_format=u",
            "type" : "file",
            "uri" : "statistics:table:index-3-7253336746667145592",
            "LSM" : {
                ...
            },
            "block-manager" : {
                ...
            },
            "btree" : {
                ...
            },
            "cache" : {
               ...
            },
            "compression" : {
               ...
            },
            "cursor" : {
               ...
            },
            "reconciliation" : {
               ...
            },
            "session" : {
               ...
            },
            "transaction" : {
               ...
            }
        },
        "borough_1_cuisine_1" : {
            "metadata" : {
                "formatVersion" : 6,
                "infoObj" : "{ "v" : 1, "key" : { "borough" : 1, "cuisine" : 1 }, "name" : "borough_1_cuisine_1", "ns" : "blogs.posts" }"
        },
        "creationString" : "allocation_size=4KB,app_metadata=(formatVersion=6,infoObj={ "v" : 1, "key" : { "borough" : 1, "cuisine" : 1 }, "name" : "borough_1_cuisine_1", "ns" : "blogs.posts" }),block_allocation=best,block_compressor=,cache_resident=0,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=0,extractor=,format=btree,huffman_key=,huffman_value=,immutable=0,internal_item_max=0,internal_key_max=0,internal_key_truncate=,internal_page_max=16k,key_format=u,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=16k,leaf_value_max=0,log=(enabled=),lsm=(auto_throttle=,bloom=,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=0,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=true,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=75,type=file,value_format=u",
        "type" : "file",
        "uri" : "statistics:table:index-4-7253336746667145592",
        "LSM" : {
            ...
        },
        "block-manager" : {
            ...
        },
        "btree" : {
            ...
        },
        "cache" : {
            ...
        },
        "compression" : {
            ...
        },
        "cursor" : {
            ...
        },
        "reconciliation" : {
            ...
        },
        "session" : {
            "object compaction" : 0,
            "open cursor count" : 0
        },
        "transaction" : {
            "update conflicts" : 0
        }
    },
    "cuisine_1" : {
        "metadata" : {
            "formatVersion" : 6,
            "infoObj" : "{ "v" : 1, "key" : { "cuisine" : 1 }, "name" : "cuisine_1", "ns" : "blogs.posts" }"
        },
        "creationString" : "allocation_size=4KB,app_metadata=(formatVersion=6,infoObj={ "v" : 1, "key" : { "cuisine" : 1 }, "name" : "cuisine_1", "ns" : "blogs.posts" }),block_allocation=best,block_compressor=,cache_resident=0,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=0,extractor=,format=btree,huffman_key=,huffman_value=,immutable=0,internal_item_max=0,internal_key_max=0,internal_key_truncate=,internal_page_max=16k,key_format=u,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=16k,leaf_value_max=0,log=(enabled=),lsm=(auto_throttle=,bloom=,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=0,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=true,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=75,type=file,value_format=u",
        "type" : "file",
        "uri" : "statistics:table:index-5-7253336746667145592",
        "LSM" : {
            ...
        },
        "block-manager" : {
            ...
        },
        "btree" : {
            ...
        },
        "cache" : {
            ...
        },
        "compression" : {
            ...
        },
        "cursor" : {
            ...
        },
        "reconciliation" : {
            ...
        },
        "session" : {
            ...
        },
        "transaction" : {
            ...
        }
    },
    "borough_1_address.zipcode_1" : {
        "metadata" : {
            "formatVersion" : 6,
            "infoObj" : "{ "v" : 1, "key" : { "borough" : 1, "address.zipcode" : 1 }, "name" : "borough_1_address.zipcode_1", "ns" : "blogs.posts" }"
             },
            "creationString" : "allocation_size=4KB,app_metadata=(formatVersion=6,infoObj={ "v" : 1, "key" : { "borough" : 1, "address.zipcode" : 1 }, "name" : "borough_1_address.zipcode_1", "ns" : "blogs.posts" }),block_allocation=best,block_compressor=,cache_resident=0,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=0,extractor=,format=btree,huffman_key=,huffman_value=,immutable=0,internal_item_max=0,internal_key_max=0,internal_key_truncate=,internal_page_max=16k,key_format=u,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=16k,leaf_value_max=0,log=(enabled=),lsm=(auto_throttle=,bloom=,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=0,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=true,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=75,type=file,value_format=u",
            "type" : "file",
            "uri" : "statistics:table:index-6-7253336746667145592",
            "LSM" : {
               ...
            },
            "block-manager" : {
               ...
            },
             "btree" : {
                ...
            },
            "cache" : {
               ...
            },
            "compression" : {
               ...
            },
            "cursor" : {
               ...
            },
            "reconciliation" : {
               ...
            },
            "session" : {
               ...
            },
            "transaction" : {
                ...
            }
        }
    },
    "totalIndexSize" : 626688,
    "indexSizes" : {
        "_id_" : 217088,
        "borough_1_cuisine_1" : 139264,
        "cuisine_1" : 131072,
        "borough_1_address.zipcode_1" : 139264
    },
    "ok" : 1
}
{
    "ns" : "guidebook.restaurants",
    "v" : 1,
    "key" : {
        "borough" : 1,
        "cuisine" : 1
    },
    "name" : "borough_1_cuisine_1"
}
db.restaurants.stats(
    {
        'indexDetails' : true,
        'indexDetailsKey' :
        {
            'borough' : 1,
            'cuisine' : 1
        }
    }
)
db.restaurants.stats(
    {
        'indexDetails' : true,
        'indexDetailsName' : 'borough_1_cuisine_1'
    }
)
{
    "ns" : "blogs.restaurants",
    "count" : 25359,
    "size" : 10630398,
    "avgObjSize" : 419,
    "storageSize" : 4104192,
    "capped" : false,
    "wiredTiger" : {
        ...
    },
    "nindexes" : 4,
    "indexDetails" : {
        "borough_1_cuisine_1" : {
            "metadata" : {
                "formatVersion" : 6,
                "infoObj" : "{ "v" : 1, "key" : { "borough" : 1, "cuisine" : 1 }, "name" : "borough_1_cuisine_1", "ns" : "blogs.posts" }"
             },
            "creationString" : "allocation_size=4KB,app_metadata=(formatVersion=6,infoObj={ "v" : 1, "key" : { "borough" : 1, "cuisine" : 1 }, "name" : "borough_1_cuisine_1", "ns" : "blogs.posts" }),block_allocation=best,block_compressor=,cache_resident=0,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=0,extractor=,format=btree,huffman_key=,huffman_value=,immutable=0,internal_item_max=0,internal_key_max=0,internal_key_truncate=,internal_page_max=16k,key_format=u,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=16k,leaf_value_max=0,log=(enabled=),lsm=(auto_throttle=,bloom=,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=0,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=true,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=75,type=file,value_format=u",
            "type" : "file",
            "uri" : "statistics:table:index-4-7253336746667145592",
            "LSM" : {
               ...
            },
            "block-manager" : {
               ...
            },
            "btree" : {
               ...
            },
            "cache" : {
               ...
            },
            "compression" : {
               ...
            },
            "cursor" : {
               ...
            },
            "reconciliation" : {
               ...
            },
            "session" : {
               ...
            },
            "transaction" : {
               ...
            }
        }
    },
    "totalIndexSize" : 626688,
    "indexSizes" : {
        "_id_" : 217088,
        "borough_1_cuisine_1" : 139264,
        "cuisine_1" : 131072,
        "borough_1_address.zipcode_1" : 139264
    },
    "ok" : 1
}
  1. MongoDB参考
  2. mongo Shell 方法
  3. 集合方法

db.collection.stats()

上一页db.collection.save()下一页db.collection.storageSize()
  • 定义
  • 行为
  • 缩放大小
  • 存储引擎
  • 意外关机后的准确性
  • 索引过滤器行为
  • 意外停机和计数
  • 进行中索引
  • 例子
  • 基本统计查询
  • 带有比例的统计查询
  • 带索引详细信息的统计查找
  • 带有过滤索引详细信息的统计信息查找

scale

number

可选的。输出中使用的比例显示项目的大小。默认情况下,输出显示bytes中的大小。要显示千字节而不是字节,请指定1024 value 1024。 如果您指定非整数比例因子,则MongoDB将使用指定因子的整数部分。例如,如果将比例因子指定为1023.999,则MongoDB将使用1023该比例因子。 从4.2版开始,输出包括scaleFactor 用于缩放大小值的输出。

indexDetails

boolean

可选的。如果为true,则db.collection.stats()除收集统计信息外,还返回 index details 仅适用于WiredTiger存储引擎。 默认为false。

indexDetailsKey

document

可选的。如果indexDetails是true,则可以使用indexDetailsKey通过指定索引 key 规范来过滤索引详细信息。只返回与indexDetailsKey完全匹配的索引。 如果找不到匹配项,indexDetails将显示所有索引的统计信息。 使用getIndexes()发现索引键。你不能将indexDetailsKey与indexDetailsName一起使用。

indexDetailsName

string

可选的。如果indexDetails是true,则可以使用indexDetailsName通过指定索引name来过滤索引详细信息。只返回与indexDetailsName完全匹配的索引名称。 如果找不到匹配项,indexDetails将显示所有索引的统计信息。 使用getIndexes()来发现索引名称。你不能将indexDetailsName与indexDetailsField一起使用。

db.collection.stats(<number>)

返回值:

包含有关指定集合的统计信息的文档。请参阅collStats以获取返回统计信息的细分。

定义
行为
例子