美文网首页
MongoDB在分片集群上count统计出的数量可能会不正确

MongoDB在分片集群上count统计出的数量可能会不正确

作者: 不胖的胖大海 | 来源:发表于2017-11-03 14:32 被阅读0次

On a sharded cluster, count can result in an inaccurate count if orphaned documents exist or if a chunk migration is in progress.

To avoid these situations, on a sharded cluster, use the $group stage of the db.collection.aggregate() method to $sum the documents. For example, the following operation counts the documents in a collection:

db.collection.aggregate(
   [
      { $group: { _id: null, count: { $sum: 1 } } }
   ]
)

To get a count of documents that match a query condition, include the $match stage as well:

db.collection.aggregate(
   [
      { $match: <query condition> },
      { $group: { _id: null, count: { $sum: 1 } } }
   ]
)

参见文档:https://docs.mongodb.com/manual/reference/command/count/

相关文章

  • MongoDB在分片集群上count统计出的数量可能会不正确

    On a sharded cluster, count can result in an inaccurate c...

  • Mongodb分片集群搭建

    MongoDb分片集群搭建 基于mongodb3.6 分片集群的权限控制 Brief: 内部通过keyfile控制...

  • Mongodb 分片集群

    在单台服务器上做 Mongodb分片集群测试 27080 ...

  • MongoDB 存储引擎

    简单回顾 上次我们说到了关于 mongodb 的集群,分为主从集群和分片集群,对于分片集群中的分片这里需要注意如下...

  • MongoDB分片集群搭建

    本文主要介绍了mongoDB分片集群概念,以及分片集群搭建过程,方便下次参考。 概念 分片(sharding)是一...

  • 分片集群中的分片集合

    分片集群中的分片集合 MongoDB 中 分片集群有专门推荐的模式,例如 分片集合 它是一种基于分片键的逻辑对文档...

  • (五)分片

    1、什么是分片 在Mongodb里面存在另一种集群,就是分片技术,可以满足MongoDB数据量大量增长的需求...

  • MongoDB 分片

    分片 在Mongodb里面存在另一种集群,就是分片技术,可以满足MongoDB数据量大量增长的需求。 当Mongo...

  • MongoDb知识点整理(二)

    分页查询统计数量#统计全部数量db.test.count()#统计特定条件的数量db.test.count({us...

  • elasticsearch-基本查询API语法整理

    常用查询 关闭服务 查询集群健康 修改复制分片的数量 创建索引并设置分片数 计算集群中的文档数量 添加 修改 删除...

网友评论

      本文标题:MongoDB在分片集群上count统计出的数量可能会不正确

      本文链接:https://www.haomeiwen.com/subject/xustmxtx.html