开发者社区> 问答> 正文

分片集群中,如何将集合进行分片

分片集群中,如何将集合进行分片

展开
收起
不变的狗子 2021-09-28 15:13:49 927 0
1 条回答
写回答
取消 提交回答
  • 热爱技术

    mongoDB 将数据进行分片支持集合级别,已经被分 片的集合被切分成多份保存在 shard 上

    sh.enableSharding("<database>") 
    ·<database> // eg: "record"
    Example : sh.enableSharding("records")
    sh.shardCollection("<database>.<collection>", { 
    <key> : <direction>, ... } ) 
    ·<key> : 分片键字段的名字
    ·<direction> : {1 | -1 |"hashed"} 。1 | -1 : 基于
    范围分片键,"hashed" : 哈希分片键
    

    举个例子:

    “Example : sh.shardCollection("records.people", 
    { zipcode: 1 } )”对 records.people 集合进行分片,
    这是一个基于 zipcode 的范围分片。
    

    image.png

    资源来源:电子书《玩转MongoDB从入门到实战》,下载链接:https://developer.aliyun.com/topic/download?id=1060

    2021-09-28 15:15:43
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Codis 集群演化与 Redis 异步迁移 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载