• MongoDB对集合分片


    1 创建数据库,直接use database_name 切换至你想创建的数据库。

    mongos> use DataPlatform
    switched to db DataPlatform

    2 创建集合 

    mongos> db.createCollection("risk_dag_hive_to_mongo", {"autoIndexId":true})
    {
    	"note" : "the autoIndexId option is deprecated and will be removed in a future release",
    	"ok" : 1
    }

    3 首先要对库DataPlatform开启分片功能

    mongos> sh.enableSharding("DataPlatform");
    { "ok" : 1 }

    可以通过 命令验证

    sh.status()

    4 对集合开启分片 

    mongos>  sh.shardCollection("DataPlatform.risk_dag_hive_to_mongo",{"user_id":1})
    { "collectionsharded" : "DataPlatform.risk_dag_hive_to_mongo", "ok" : 1 }

    通过命令验证  看截图中sharded已经为true,说明开启了分片

    mongos> db.risk_dag_hive_to_mongo.stats()

    5 为数据库创建账号 

    mongos>  db.createUser(
    ...      {
    ...        user:"DataPlatform_rw",
    ...        pwd:"",
    ...        roles:[{role:"readWrite",db:"DataPlatform"}]
    ...      })
    Successfully added user: {
    	"user" : "DataPlatform_rw",
    	"roles" : [
    		{
    			"role" : "readWrite",
    			"db" : "DataPlatform"
    		}
    	]
    }
  • 相关阅读:
    第十二周 张文小组学习情况总结
    第五章
    第四章
    第三章
    软工实训--学习回顾2
    软工实训-- 学习回顾1
    构建之法——读书笔记(9)
    构建之法——读书笔记(8)
    构建之法——读书笔记(7)
    第13周张文小组学习情况总结
  • 原文地址:https://www.cnblogs.com/DBABlog/p/12926879.html
Copyright © 2020-2023  润新知